2011-02-04 20 views
0

好吧我有兩個類:圖像和場景。現在在Image頭文件中,我定義了三個私有變量:xcoord,ycoord和index(以及它們各自的公共getter方法)。C++中的類和成員變量幫助

我有另一個類名爲場景。場景不是圖像的子類。場景有兩個成員變量:int maximumImage **images。現在在Scene中,我有一些方法試圖訪問Image類的成員變量。例如:

int beginX =this->images[i].getXcoord; 
int beginY =this->images[i].getYcoord; 

不過,我得到以下錯誤:

error: request for member ‘getXcoord’ in ‘*(((Image**)((const Scene*)this)->Scene::images) + ((Image**)(((long unsigned int)i) * 8ul)))’, which is of non-class type ‘Image*’ 

scene.cpp:135: error: request for member ‘getYcoord’ in ‘*(((Image**)((const Scene*)this)->Scene::images) + ((Image**)(((long unsigned int)i) * 8ul)))’, which is of non-class type ‘Image*’ 

在我scene.cpp文件,我已經包括scene.h包括image.h的,所以我敢肯定一切都正確連接。這顯然是我的問題是什麼或將不得不提供更多信息?

回答

1

你要調用方法,所以嘗試:

int beginX = this->images[i]->getXcoord(); 
int beginY = this->images[i]->getYcoord(); 

否則編譯器正在尋找一個成員變量,而不是一個getter方法

+0

雅你是對的。勒姆修復並再次檢查,但我很確定我有更多的錯誤。 – iRobot 2011-02-04 03:37:55

0

如果this->imagesImage**,然後this->images[i]Image*

用箭頭替換點。

0

的問題是圖像數組保存類型指針

嘗試 int beginX =this->images[i]->getXcoord;

此外,如果getXcoord是你需要調用它

int beginX =this->images[i]->getXcoord();

最後你沒有一個功能需要this->其暗指如此使用

int beginX = images[i]->getXcoord();

DC

0

有兩個問題。它應該是:

int beginX = this->images[i]->getXcoord(); 

錯誤消息不允許'。'在Image *上不是一個類類型的對象。