declaring a 2D array of pointer objects
Posted
by
Tyler Stennette
on Stack Overflow
See other posts from Stack Overflow
or by Tyler Stennette
Published on 2012-04-15T05:26:26Z
Indexed on
2012/04/15
5:28 UTC
Read the original article
Hit count: 266
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.
© Stack Overflow or respective owner