I have an object which needs to destroy itself.
Can it be done?
Is the example wrong?
void Pawn::specialMoves(Coordinate const& from, Coordinate const& to, int passant) { /*...*/ m_board->replace(to, new Queen(m_colour));//replace pawn by queen } void Board::replace(Coordinate const &to, Piece* newPiece) { delete tile[to.x()][to.y()]; tile[to.x()][to.y()] = newPiece; }
delete this;
orthis->~T();
(withT
being its type). Both are valid but require lots of care to be used correctly. – Glacierm_board->replace(to, new Queen(m_colour));
has been called function void Pawn::specialMoves(...)` can not finish ` – Compte