C++ C+;中的类和成员变量帮助+;

C++ C+;中的类和成员变量帮助+;,c++,C++,好的,我有两个类:图像和场景。现在在映像头文件中,我定义了三个私有变量:xcoord、ycoord和index(以及它们各自的公共getter方法) 我还有一个班叫Scene。场景不是图像的子类。场景有两个成员变量:int max和Image**images。现在在场景中,我有一些方法试图访问Image类的成员变量。例如: int beginX =this->images[i].getXcoord; int beginY =this->images[i].getYcoord; 但是

好的,我有两个类:图像和场景。现在在映像头文件中,我定义了三个私有变量:xcoord、ycoord和index(以及它们各自的公共getter方法)

我还有一个班叫Scene。场景不是图像的子类。场景有两个成员变量:
int max
Image**images
。现在在场景中,我有一些方法试图访问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,所以我非常确定所有内容都已正确链接。我的问题是什么?或者我必须提供更多信息吗?

您想调用方法,请尝试:

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

否则,编译器将查找成员变量而不是getter方法

如果
this->images
图像**
,则
this->images[i]
图像*


将点替换为箭头。

问题在于图像数组包含指向类的指针

试一试
int beginX=this->images[i]->getXcoord

另外,如果getXcoord是一个函数,则需要像这样调用它

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

最后,你不需要
这个->
它的含义,所以请使用它

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


DC有两个问题。应该是:

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

错误消息不允许在不是类类型对象的映像*上使用“.”运算符。

Ya您是对的。让我修正一下,然后再检查一遍,但我很肯定会有更多的错误。