Calculating the Number of Elements in a C++ Array
1 | |
关键代码
1 | |
这一段是网上流行(?)计算数组元素个数的代码
但是在数组为指针的时候,经常会出错(C6384)
解决方法:
使用结构(struct)传递
struct a{
int b[5]}
xxx(struct a)
{
sizeof(a.b);
}
似乎是因为在传递的时候,数组变成了一个指针…
1 | |
Key code
1 | |
This piece is the widely circulated (?) code for calculating the number of elements in an array.
However, it often fails (C6384) when the array is a pointer.
Solution:
Use a structure (struct) for passing.
struct a{
int b[5]}
xxx(struct a)
{
sizeof(a.b);
}
It seems that during passing, the array becomes a pointer…
Calculating the Number of Elements in a C++ Array
https://tokisaki.top/blog/cpp-array-element-count/