Tyler Stennette
Tyler Stennette

Reputation: 53

declaring a 2D array of pointer objects

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.

Upvotes: 0

Views: 957

Answers (1)

David Schwartz
David Schwartz

Reputation: 182865

The compiler error indicates that the compiler doesn't know what a Rook is and doesn't know that it's derived from Pieces. It looks like a missing #include.

Upvotes: 1

Related Questions