Look at this example
class Player {
ChessEngine* ce;
public:
makeMove() {
ce.addMove();
}
};
class ChessEngine {
Player* p1;
list<move*> moveList;
public:
ChessEngine() {
p1 = new Player;
}
Player* getPlayer() {
return p1;
}
void addMove() {
}
};
int main()
{
ChessEngine chessEngine1;
return 0;
}
I have restructured the problem so that it can be understood.
Here ChessEngine knows about Player to call makeMove.
Player needs to call addMove of object chessEngine.
My problem is how **ChessEngine * ce attribute of class Player* can be initialised as pointer to object chessEngine1?
This can be done by adding constructor to
Player:and passing
ChessEngineas a parameter: