Hi!
Can someone help me check what is going on with my code?
class Piece{
protected:
shared_ptr<Cell> cell;
bool skipObstacles;
void MoveToCell(shared_ptr<Cell> startingCell);
public:
Faction faction;
PieceType type;
Piece(shared_ptr<Cell> startingCell, Faction faction, PieceType type, bool skipObstacles);
/// @brief define the basic ruleset of a particular chess piece regardless of obstacles or legality
virtual void SetPieceOnCell() = 0;
virtual vector<int> GetPieceDefaultPath() = 0;
};
class King : public Piece{
public:
void SetPieceOnCell() override;
King(shared_ptr<Cell> startingCell, Faction faction): Piece(startingCell, faction, KING, false) {}
vector<int> GetPieceDefaultPath() override;
};
King has implementation of SetPieceOnCell method as follows:
void King::SetPieceOnCell(){
shared_ptr<King> my_ptr(this);
this->cell->SetPieceOnCell(my_ptr);
}
In Piece, there is a method called MoveToCell that has the following implementation
void Piece::MoveToCell(shared_ptr<Cell> startingCell){
if(this->cell != nullptr){
this->cell->SetCellEmpty();
}
this->cell = nullptr;
this->cell = startingCell;
this->SetPieceOnCell();
}
for some reason, SetPieceOnCell is calling virtual method defined in the base class instead of the derived class
vector<shared_ptr<Piece>> white_pieces;
vector<shared_ptr<Piece>> black_pieces;
white_pieces.emplace_back(make_shared<King>(King(cells[4][7], Faction::WHITE_FACTION)));