error LNK2001:unresolved external symbol "xxx:static xxx"

时间:2021-03-08 11:40:28

一般是在类的头文件里定义了某个static变量而没有在类的 Implemention 里去初始化(也许不是这么称呼)这个变量。

比如在 xxdlg.h 中写了如下代码

   1: class CxxDlg {

   2:     ...

   3: private:

   4:     static RECT m_wndRect;

   5:     ...    

   6: };

那么,我们应该在 xxdlg.cpp 中添加如下代码,它必须放在全局环境中,不能在某个类或者函数中
   1: #include "xxdlg.h"

   2: ...

   3: CxxDlg::CxxDlg() {

   4: }

   5: ...

   6: RECT CxxDlg::m_wndRect;