Skip to main content
1 of 3
Lars Viklund
  • 4.1k
  • 1
  • 19
  • 23

sizeof(T*) is the size of a pointer, not the size of whatever sequence of objects it points to.

If you want the number of elements of an array, either use a macro at the place where it's still an array, use a more friendly array type (std::array), or template it:

template <typename T, size_t N>
size_t array_count(T const (&)[N]) {
  return N;
}
Lars Viklund
  • 4.1k
  • 1
  • 19
  • 23