我很难解释这个问题,下面是我的代码的简单概述:
想象一下我有一个叫“人物”的类
#include "myEnums"
#include "weapon"
character {
protected:
string characterName;
weapon* myWeapon;
public:
string getCharacterName();
void setCharacterName( string );
string getMyWeapon();
void setMyWeapon();
}然后,在“setMyWeapon”中,我使用了以下简化代码。
void character::setMyWeapon() {
this->myWeapon = new weapon("longsword");
//this->myWeapon = new weapon(myEnums::LONGSWORD); //Ideally this
}
string getMyWeapon() {
return this->myWeapon.tostring();
}但当我键入“.”因为“myWeapon”没有会员,有人知道什么吗?假设“tostring”是在“武器库”中定义的。
发布于 2013-10-22 20:31:21
由于myWeapon是一个指针,您需要取消引用它才能访问切入点的成员:
myWeapon->tostring()
// ^^^^https://stackoverflow.com/questions/19527696
复制相似问题