Undef 引用非 Q 中的构造函数和析构函数中的 vtable
我有一个基类 GameObject,它当前是 Camera 和 SolidObject 的父类。 SolidObject 是 Player 和 GameMap 的父对象。由于某种原因,我只在 GameMap 的构造函数和析构函数中获得对 vtable 的未定义引用。这是代码(我不会包含相机或播放器)。注意:GameObject 和 SolidObject 位于 World.h 中,因为它们很小并且需要连接。我只会包含与这些类和 GameMap 相关的内容。
我切换了继承,因此 GameMap 继承自 GameObject 而不是 SolidObject,但它仍然会导致相同的错误。
World.h
class GameObject
{
public:
World* parent;
unsigned int objID;
virtual void step();
};
class SolidObject : public GameObject
{
public:
float xpos, ypos, zpos;
float xrot, yrot, zrot;
};
World.cpp
void GameObject::step()
{
}
GameMap.h
class GameMap : public GameObject
{
private:
WFOBJ model;
public:
GameMap(World* world, char* modelFile, char* textureFile);
~GameMap();
void step();
void setModel();
};
GameMap.cpp
void step()
{
}
GameMap::GameMap(World* world, char* modelFile, char* textureFile)
{
model.loadFile(modelFile, textureFile);
objID = world->addObject(this);
parent = world;
}
GameMap::~GameMap()
{
parent->removeObject(objID);
}
I've got a base class, GameObject, which currently parents Camera and SolidObject. SolidObject parents Player and GameMap. For some reason I'm only getting undefined references to vtable in the constructor and destructor of GameMap. Here's the code (I won't include Camera or Player). NOTE: GameObject and SolidObject are in World.h because they are small and need to be connected. I will only include stuff related to those classes and GameMap.
I switched the inheritance so GameMap inherits from GameObject instead of SolidObject, but it still causes the same error.
World.h
class GameObject
{
public:
World* parent;
unsigned int objID;
virtual void step();
};
class SolidObject : public GameObject
{
public:
float xpos, ypos, zpos;
float xrot, yrot, zrot;
};
World.cpp
void GameObject::step()
{
}
GameMap.h
class GameMap : public GameObject
{
private:
WFOBJ model;
public:
GameMap(World* world, char* modelFile, char* textureFile);
~GameMap();
void step();
void setModel();
};
GameMap.cpp
void step()
{
}
GameMap::GameMap(World* world, char* modelFile, char* textureFile)
{
model.loadFile(modelFile, textureFile);
objID = world->addObject(this);
parent = world;
}
GameMap::~GameMap()
{
parent->removeObject(objID);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 GameMap.cpp 中的
step()
定义 - 它缺少类名。它应该被声明为void GameMap::step()
。该错误实际上应该提到找不到step
的定义,但是 如精彩的 C++ 常见问题解答中所述,您可能会收到此错误。Look at
step()
's definition in GameMap.cpp - it's missing the class name. It should have been declared asvoid GameMap::step()
. The error should actually have mentioned thatstep
's definition cannot be found, but as explained in the great C++ FAQ, you might get this error instead.