declaring a 2D array of pointer objects
- by Tyler Stennette
I'm having a tough time figuring out how to instantiate a 2D array of pointer objects. Here is how I'm doing it:
Pieces* chessBoard[9][9];
When I want to set it to an actual object pointer, I'm doing the following:
chessBoard[1][1] = new Rook(p1Rook);
Rook is a class that inherits attributes from the Pieces class and p1Rook is a char variable set to 'R'. This class also implements virtual functions (not pure virtual) from Pieces such as move() or getPiece() that are unique to the particular chess piece. However, when I compile my program, I get the following error:
ChessBoard.cpp:69: error: expected type-specifier before ‘Rook’
ChessBoard.cpp:69: error: cannot convert ‘int*’ to ‘Pieces*’ in assignment
Can someone please explain what I should change to get rid of this rather annoying persistent error? I would appreciate it.