Using Apple Clang 12.0.0 to compile this code:
int my_array[10];
int arr_size = sizeof(my_array) / sizeof(decltype(my_array[0]))
And getting this warning/error:
Expression does not compute the number of elements in this array; element type is 'int', not 'decltype(my_array[0])' (aka 'int &')
Note, this is simplified code. In the real code instead of 'int' there's a class type, instead of '10' there's an expression.
Why am I getting this warning, and what is the correct way to calculate the array size without warnings?
Aucun commentaire:
Enregistrer un commentaire