一段时间以来,我一直在努力寻找解决方案。我想从具有静态指针的类继承,但我得到错误 LNK2001: unresolved external symbol "protected: static class cGame * cEvent::mGame" (?mGame@cEvent@@1PAVcGame@@A)
最理想的是,我只需初始化我的类 cEvent 一次,然后不要在继承的类中传递指针。
#ifndef EVENT_H
#define EVENT_H
#include "game.h"
class cEvent
{
protected:
static cGame* mGame;
public:
cEvent(){;}
virtual void doEvent(){;}
};
class cEventExitButton: public cEvent
{
private:
public:
cEventExitButton(cGame *g){mGame = g;}
void doEvent(){mGame->getWindow()->close();}
};
#endif