在cpp文件中使用类的静态static数据报连接错(LNK2001)

来源:互联网 发布:空间数据库设计 编辑:程序博客网 时间:2024/05/28 15:16

现有如下一个类:

class CPlayer{public:...private:static CPlayer* pthis;...};

在cpp中使用pthis指针会报如下链接错:

error LNK2001: unresolved external symbol "private: static class CPlayer * CPlayer::pthis" (?pthis@CPlayer@@0PAV1@A)Debug : fatal error LNK1120: 1 unresolved externals


只需要在cpp中添加静态成员的定义即可。

CPlayer* CPlayer::pthis;