//GUITEXT
class guitext : public entity {
public:
guitext(graphics *gfx, std::string _text, float _x, float _y,
float _size, float timeToLive);
bool update(float deltaTime, gameworld *world);
void draw(graphics *gfx);
};
void guitext::draw(graphics *gfx) { printf("draw"); }
//ENTITY
class entity {
public:
virtual bool update(float deltaTime, gameworld *world)
{ return false; }
virtual void draw(graphics *gfx) { }
};
//GAMEWORLD
void gameworld::addEntity(entity e) { entitys.push_back(e); }
//MAIN
for(int i = 0; i < (int)entitys.size(); i++) { entitys[i].draw(gfx); }
我的游戏世界类中有一个向量。当我将 guitext 实体添加到该向量时,我希望它调用 guitext::draw() 函数。但是基类函数正在被调用。我究竟做错了什么?
你做了一个向量entity
。那些物体always有类型entity
。如果你想调用多态性,它们需要是指针或引用。怎样才能得到一个向量entity
存储一个guitext
?没有足够的空间,它不知道如何销毁它等等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)