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

一般是在类的头文件里定义了某个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;
posted @ 2013-08-29 16:20  琼'  阅读(367)  评论(0编辑  收藏  举报