我有一个关于取消引用数组的小问题。我在课堂上有这样的方法
T* foo()
{
// create specific array of objects in here
return (array)
}
foo2()
{
myNewArray = *foo();
// exactly the same algorithm as in foo to create checkArray
cout << sizeof(myNewArray) << sizeof(checkArray) << endl;
}
我得到两个不同的结果,但我希望它们是相同的?
好的,关于代码的附加信息:
vec4* getGridAttr()
{
float xval = -0.5;
float yval = -0.75;
float xval2 = -0.5;
float yval2 = -0.75;
vec4 pointsGrid[100];
for (int i=0;i<42;i++)
{
//Draw horizontal lines
if (i % 2 == 0) pointsGrid[i] = vec4(xval, yval, 0.0,1);
else if (i % 2 != 0) {
pointsGrid[i] = vec4((xval+0.75), yval, 0.0,1);
yval += 0.075;
}
}
for (int j=42;j<64;j++)
{
//Draw horizontal lines
if (j % 2 != 0)
{
pointsGrid[j] = vec4(xval2, yval2, 0.0,1);
xval2 += 0.075;
}
else if (j % 2 == 0) {
pointsGrid[j] = vec4(xval2, -yval2, 0.0,1);
}
}
return (pointsGrid);
}
在我的其他方法中,我有这个:
void display( void )
{
vec4 points1[100];
//code here populates points1 exactly the same as in getGridAttributes,
cout << "points1 : " << sizeof(points1) << " " << " pointsFromGridAttr : " << sizeof(*getGridAttr()) << endl;
}
输出为 points1 : 1600 pointsFromGridAttr 16