Maybe your colleague meant that using this expression with pointers will give an unexpected result. This mistake is made very often by beginners. For example
void f( unsigned char data[] )
{
int data_len = sizeof(data) / sizeof(data[0]);
//...
}
//...
unsigned char data[] = {1,2,3,4,5};
f( data );
So in general case it would be more safely to use a template function instead of the expression. For example
template <class T, size_t N>
inline size_t size( const T ( & )[N] )
{
return N;
}
Take into account that there is template structure std::extent
in C++ 11 that can be used to get the size of a dimension.
For example
int a[2][4][6];
std::cout << std::extent<decltype( a )>::value << std::endl;
std::cout << std::extent<decltype( a ), 1>::value << std::endl;
std::cout << std::extent<decltype( a ), 2>::value << std::endl;