Hello, I've got the following problem:
I want a two-dimensional dynamic array of pointers to classes. In the two dimensional dynamic array will be pointers to another class. So that I can call m_pPointer[x][y] that points to a class.
I already got this for a one-dimensional dynamic array of pointers to classes. I did that on the next way:
Code:
CClassA::CClassA(int row)
{
int x;
m_pPointer = new CClassB*[row];
for(x=0; x<row; x++)
{
m_pPointer[x] = new CClassB;
}
}
With this code I've created an array of pointers to the class CClassB. When row = 10, each m_pPointer[0] to m_pPointer[9] points to a class CClasseB.
To do this for a two-dimensional array I thought I could do it on this was:
Code:
CClassA::CClassA(int row, int col)
{
int x, y;
m_pPointer = new CClassB*[row];
for(x=0; x<row; x++)
{
m_pPointer[x] = new CClassB[col];
for(y=0; y<col; y++)
{
m_pPointer[x][y] = new CClassB;
}
}
}
With this code I hoped that I would have a 2d array with pointers to classes, so that I could say:
Code:
cout << m_pPointer[0][0];
But unfortunately I C++ doesn't think so, I get the following error:
Code:
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class CClassB' (or there is no acceptable conversion)
What am I doing wrong?