传递给 C++ 函数的数组大小? [英] size of array passed to C++ function?
本文介绍了传递给 C++ 函数的数组大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
确定传递给函数的数组大小
如何获取传递给函数的 C++ 数组的大小?
How can I get the size of a C++ array that is passed to a function?
在下面的代码中,sizeof(p_vertData)
没有返回正确的数组大小.
In the following code, the sizeof(p_vertData)
does not return the correct size of the array.
float verts[] = {
-1.0,1.0,1.0,
1.0,1.0,1.0,
1.0,-1.0,1.0,
-1.0,-1.0,1.0,
-1.0,1.0,-1.0,
1.0,1.0,-1.0,
1.0,-1.0,-1.0,
-1.0,-1.0,-1.0
};
void makeVectorData(float p_vertData[]) {
int num = (sizeof(p_vertData)/sizeof(int));
cout << "output: " << num << endl;
};
我做错了什么?
推荐答案
你不能 - 数组在作为函数参数传递时衰减为指针,所以 sizeof
不会帮助你.
You can't - arrays decay to pointers when passed as function parameters so sizeof
is not going to help you.
这篇关于传递给 C++ 函数的数组大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文