I am making a chess game and when I click on a square I want to know what piece is there. Since there are more than 1 type of pieces it would be annoying to have more variables in the Square structure.
So I have though about a class named Piece which is the parent of each type of Piece.
Example.
class Pawn : public Piece
I want to achieve a Square structure that looks something like this :
struct Square { Piece *piece };
Now, I want to initialize the piece variable like this :
piece = new Pawn(); // or what type of piece it should be.
My problem is that by doing this I can still only access Piece's class functions and not the Pawns ones.
How do I achieve such thing as having only 1 parent which can access everything his children have?