2013-05-06 1 views
0

Qt의 게시물 제목에 설명 된 오류가 발생했습니다.오류 : C2248 : 'QGraphicsItem :: QGraphicsItem': 'QGraphicsItem'클래스에 선언 된 비공개 멤버에 액세스 할 수 없습니다.

나는 "ball"이라는 클래스 호출을 가지고 있으며 QGraphicsItem을 상속받은 "tableItem"클래스를 상속받습니다. 프로토 타입 디자인 패턴을 사용하려고 시도하고 있으므로 볼 클래스 내부에 복제 메서드가 포함되어 있습니다.

가 여기 내 코드입니다 : 볼 헤더와 클래스

#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 

및 공 클래스의 경우 :

#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() 
{} 

/* This is where the problem is. If i omitted this method, the 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; 
} 

tableItem 헤더 :

#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 

과 tableitem 클래스 :

#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; 
} 

문제를 찾아서 stackoverflow 포럼을 검색하면 qgraphicsitem 생성자 또는 변수 중 일부가 개인용으로 선언되어 나타납니다. 따라서이 문제가 발생합니다. 일부 솔루션은 스마트 포인터의 사용을 나타내지 만 제 경우에는 작동하지 않습니다.

도움을 주시면 감사하겠습니다.

+0

어떤 줄에 오류가 있습니까? –

+0

오류 메시지가 클래스 –

+0

공의 복제 메서드의 반환 진술 것 같다 언급 한 이후 당신이'QGraphicsItem' 헤더에 대한 링크를 제공 할 수 있다면 유용 할 것 같아요 : ball * ball :: clone() const { 새 공을 반환합니다 (* this); } 하지만 Qt는 오류를 나타냅니다 내가 확실하지 않다 tableItem의 header..thus의 끝에서 온다 .. – ImNoob

답변

1

자신 만의 복사본 생성자를 제공하면 도움이 될 수 있습니다.

기본 복사 생성자는 클래스와 그 부모의 모든 데이터 멤버를 복사하려고 시도합니다.

자신의 복사본 생성자에서 가장 적절한 복사 방법을 사용하여 데이터 복사를 처리 할 수 ​​있습니다.

+0

예 문제가 복사 생성자 것 같습니다. 내 자신의 복사본 생성자를 제공하고 그것은 work.thanks 보인다 :) – ImNoob

관련 문제