When passing an array to a function, you usually pass the length of the array along with it. You can compute the size of the array with sizeof(myArray)/sizeof(myArray[0])
, which works just fine.
However, if you try to do this within the function that you pass the array to, this doesn't return the length of the array - eg. if it is an int
array, it returns 1, if it is a double
array, it returns 0.
Why is that so and is there any way to compute the size of an array that was passed as a parameter?
template <typename T, size_t N> void f(T(& myArray)[N])