I am working on a chess game in C++, and each type of piece has its own class, which all inherit the "Space" class. For the board, I have an two dimensional 8x8 array of Space, declared as Space board[8][8] {}
the brackets being filled with different instances of the piece classes.
I need to make an if
statement to check if a space is empty. This means, I need to check a location on the array if it is empty. The current code for the if statement is
if(board[0][0] == wRook1 {}
Please note: wRook1
is an instance of the Rook class, which inherits the Space class. However, I get an error saying that the
operator == is not valid for the operands Space == Space.
How do I make the custom class Space
work with the == operator?
Currently the Space class simply has a constructor, as it is only used to be an overarching type for the pieces.