我一直在试图寻找一个解决方案.我想继承一个带有静态指针的类,但我是geterror LNK2001:未解析的外部符号"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
Run Code Online (Sandbox Code Playgroud)