0

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.

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yup that's what it was. Thanks for the help David.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.