У меня проблема с перегрузкой оператора присваивания. Я получаю в консоли ошибку «терминатор, вызываемый рекурсивно».
Я относительно новичок в структурах данных, и у меня возникли проблемы с отладкой этой проблемы.
Вот объявление класса:
class Player
{
public:
Player(const unsigned int x_, const unsigned int y_, const char i_);
Player(const Player& p_);
~Player();
unsigned int getX() const;
unsigned int getY() const;
char getI() const;
void updatePosition(int newX, int newY);
Player& operator=(const Player& p_);
private:
struct Position{
unsigned int x;
unsigned int y;
};
Position* pos;
char i;
};
А вот реализация функции operator =:
Player& Player::operator=(const Player& p_)
{
delete pos;
pos = nullptr;
pos = new Position();
pos->x = p_.getX();
pos->y = p_.getY();
i = p_.getI();
return *this;
}