I have this small question about dereferencing arrays. I have a method in class like this
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;
}
I get two different results, but I expect them to be the same?
Ok, so the additional information about the code:
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);
}
and in my other method, i have this:
void display( void )
{
vec4 points1[100];
//code here populates points1 exactly the same as in getGridAttributes,
cout << "points1 : " << sizeof(points1) << " " << " pointsFromGridAttr : " << sizeof(*getGridAttr()) << endl;
}
The output is points1 : 1600 pointsFromGridAttr 16