playersystem和rocketsystem继承自system,playersystem包含指向rocketsystem的指针。当我尝试访问 Rocketsystem 应该继承的系统中的任何内容时,我遇到了错误。运行时错误是“无法评估表达式”我在 Visual Studio 中设置了一个断点,将鼠标悬停在位置向量上,它说。
编辑:对于后代,这就是我正在做的事情,事实证明它正在工作,我只是出于某种原因将火箭系统指针设置为 null
class Vector2D
{
public:
float x;
float y;
Vector2D(float x_, float y_) :x(x_),y(y_){}
};
class System
{
protected:
vector<Vector2D> position;
public:
void addEntity(Vector2D newPos)
{
position.push_back(newPos);
}
};
class projectile :public System
{
public:
void createRocket(Vector2D pos)
{
addEntity(pos);
}
};
class player : public System
{
public:
projectile* rocketSystem;
void init(projectile* rocketsys){rocketSystem = rocketsys;}
void fireRocket(Vector2D pos)
{
rocketSystem->createRocket(pos);
}
};
int main (int argc, char * const argv[])
{
player* PlayerSystem = new player;
projectile* RocketSystem = new projectile;
PlayerSystem->init(RocketSystem);
PlayerSystem->fireRocket(Vector2D(0,0));
return 0;
}