c++ - error: C2248: 'QGraphicsItem::QGraphicsItem' : cannot access private member declared in class 'QGraphicsItem' -


i encountered error described on post title in qt.

i have class call "ball", , inherits class call "tableitem" inherits qgraphicsitem. i'm trying use prototype design pattern, , have included clone method inside ball class.

here's code snippet: ball header , class

#ifndef ball_h #define ball_h  #include <qpainter> #include <qgraphicsitem> #include <qgraphicsscene> #include <qtcore/qmath.h> #include <qdebug> #include "table.h" #include "tableitem.h"  class ball : public tableitem { public:     ball(qreal posx, qreal posy, qreal r, qreal vx, qreal vy, table *table1);     ~ball();       virtual ball* clone() const;      virtual void initialise(qreal posx, qreal posy, qreal r, qreal vx, qreal vy);  private:      table *t;  };  #endif // ball_h 

and ball class:

#include "ball.h"  ball::ball(qreal posx, qreal posy, qreal r, qreal vx, qreal vy, table *table1):     tableitem(posx, posy, r, vx, vy),     t(table1) {}  ball::~ball() {}  /* problem is. if omitted method, code runs no problem! */ ball *ball::clone() const {     return new ball(*this);  }  void ball::initialise(qreal posx, qreal posy, qreal r, qreal vx, qreal vy) {     startx = posx;     starty = posy;     setpos(startx, starty);      xcomponent = vx;     ycomponent = vy;      radius = r; } 

the tableitem header:

#ifndef tableitem_h #define tableitem_h  #include <qpainter> #include <qgraphicsitem> #include <qgraphicsscene>  class tableitem: public qgraphicsitem { public:     tableitem(qreal posx, qreal posy, qreal r, qreal vx, qreal vy);      virtual ~tableitem();      qreal getxpos();     qreal getypos();     qreal getradius();   protected:     qreal xcomponent;     qreal ycomponent;      qreal startx;     qreal starty;     qreal radius;  };  #endif // tableitem_h 

and tableitem class:

#include "tableitem.h"  tableitem::tableitem(qreal posx, qreal posy, qreal r, qreal vx, qreal vy) {     this->xcomponent = vx;     this->ycomponent = vy;      this->startx = posx;     this->starty = posy;      this->radius = r; }  tableitem::~tableitem() {} qreal tableitem::getxpos() {     return startx; }  qreal tableitem::getypos() {     return starty; }  qreal tableitem::getradius() {     return radius; } 

googling problem , searching stackoverflow forum seems indicate of qgraphicsitem constructor or variables declared private, , give rise this. solution indicates use of smart pointer, doesn't seem work in case.

any appreciated.

providing own copy constructor may help.

the default copy constructor tries copy data members class , parents.

in own copy constructor, can handle copying of data using appropriate way of copying.


Comments