Есть два вопроса по одному проекту.
Пишу шахматы на С++ и использую Qt. Для каждый фигуры сделал свой класс и унаследовал это все от своего класса figure. Переменные класса figure не создаю, создаю переменные наследованных классов (pawn, king и прочее) и добавляю их в вектор vector.
Преподаватель в вузе увидел код, в котором в классе figure объявлены пустые конструктор и деструктор и попросил ответить на вопрос, почему так делать нельзя, самостоятельно не нашел ответа и взываю к вашей помощи.
Когда к вектору vector white пытаюсь применить:
white.erase(white.begin() + 1)
выдает 2 ошибки:
- use of deleted function 'figure& figure::operator=(const figure&)'
- use of deleted function 'QObject& QObject::operator=(const QObject&)'
Вот файл Figure.h
#ifndef FIGURE_H
#define FIGURE_H
#include <QObject>
#include <QVector>
using namespace std;
class figure : public QObject
{
Q_OBJECT
public:
figure();
int x;
int y;
bool alive;
bool active;
bool castling = true;
figure (const figure &other);
figure& operator=(const figure &other);
~figure();
Figure.cpp
#include "figure.h"
figure::figure()
{
}
figure::figure(const figure &other)
{
this->x = other.x;
this->y = other.y;
this->alive = other.alive;
this->active = other.active;
this->castling = other.castling;
}
figure operator = (const figure &other)
{
if (this != &other)
{
this->x = other.x;
this->y = other.y;
this->alive = other.alive;
this->active = other.active;
this->castling = other.castling;
}
return *this;
}
figure::~figure()
{
}