I've tried:
template <typename T,unsigned S>
unsigned getArraySize(const T (&v)[S]) { return S; }
after Motti's answer https://stackoverflow.com/a/18078435/512225
but I've got this message:
error C2265: '' : reference to a zero-sized array is illegal
What's wrong with my compiler?
I gave a look at this page: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/4b78bcef-4c33-42f1-a4c5-fb6f702ced0b/vs6-c-compile-error-using-getaddrinfo so I tried this solution:
template <typename T,unsigned S>
unsigned getArraySize(const T v[S]) { return S; }
this compiles, but when I try to use it:
double myX[2] = {7,3};
std::cout << getArraySize(myX) << std::endl;
I get a compilation error:
error C2783: 'unsigned int __cdecl getArraySize(const T [])' : could not deduce template argument for 'S'
Beside changing the compiler, is there a workaround I can use to get the array's size?