I'm trying to get to the bottom of an error, I wonder if you could help please? I'm having a bit of an issue with array pointers at the moment. I have three classes, one parent, and two children so to speak. One of the children has a 2D array of type struct, and I'm trying to access the elements of this from the other child.
I was wondering, is this code valid with the correct format/syntax for my array pointers? OChild1 creates and fills out the 2D array, I'm saving a pointer to that in Parent, and passing that pointer to OChild2, and then plan on using the contents of the array for further processing.
struct BOARDTILE
{
float fPosX;
float fPosY;
BOARDTILES()
{
fPosX = 0.0f;
fPosY = 0.0f;
}
};
class CChild1
{
public:
BOARDTILE BoardTileArray[18][18];
CChild1()
{
}
writeBoardTileArray()
{
for (int i = 0; i <= 17; i++)
{
for (int j = 0; j <= 17; j++)
{
BoardTileArray[i][j].fPosX = (float) i * 5.0f;
BoardTileArray[i][j].fPosY = (float) j * 7.0f;
}
}
}
};
class CChild2
{
public:
BOARDTILE (*pBoardTileArray)[18][18];
float fPosX;
float fPosY;
CChild2()
{
}
void readBoardTileArray()
{
for (int i = 0; i <= 17; i++)
{
for (int j = 0; j <= 17; j++)
{
fPosX = (*pBoardTileArray[i][j]).fPosX;
fPosY = (*pBoardTileArray[i][j]).fPosY;
cout << fPosX;
cout << fPosY;
}
}
}
};
class CParent
{
public:
BOARDTILE (*pBoardTileArray)[18][18];
CChild1 OChild1;
CChild2 OChild2;
CParent()
{
OChild1.writeBoardTileArray();
pBoardTileArray = &(OChild1.BoardTileArray);
OChild2.pBoardTileArray = pBoardTileArray;
}
};