Я пытаюсь определить конструктор копирования класса, но я ошибаюсь. Я пытаюсь сделать сына QGraphicsRectItem
с помощью этого конструктора:конструктор копирования унаследованного класса
QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem * parent = 0)
здесь код
QGraphicsRectItem определяется ЛКП
QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem * parent = 0)
Cell.h, класс сына:
Cell();
Cell(const Cell &c);
Cell(qreal x, qreal y, qreal width, qreal height, QGraphicsItem * parent = 0);
Cell.cpp:
Cell::Cell() {}
/* got error defining this constructor (copy constructor) */
Cell::Cell(const Cell &c) :
x(c.rect().x()), y(c.rect().y()),
width(c.rect().width()), height(c.rect().height()), parent(c.parent) {}
Cell::Cell(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent) :
QGraphicsRectItem(x, y, width, height, parent) {
...
// some code
...
}
ошибка говорит:
/../../../../cell.cpp:7: error: class 'Cell' does not have any field named 'x'
/../../../../cell.cpp:7: error: class 'Cell' does not have any field named 'y'
/../../../../cell.cpp:7: error: class 'Cell' does not have any field named 'width'
/../../../../cell.cpp:7: error: class 'Cell' does not have any field named 'height'
/../../../../cell.cpp:7: error: class 'Cell' does not have any field named 'parent'
спасибо
Вы действительно наследуете от правого родительского класса? –
Что еще находится на линии, которая говорит 'class Cell'? –
это разрешимо: Cell :: Cell (const Cell & c): QGraphicsRectItem (c.rect(). X(), c.rect(). Y(), c.rect(). Width(), c.rect() .height()) {} Кто-нибудь знает почему? (долгое время я не являюсь моим дорогим C++) – Giquo