按照this和this的答案(相同的答案),现在这是我的代码的结构(我有CDialog1和CDialog2类)。
// in CDialog1.h
public:
static CDialog2 *ChildDialog;
// in CDialog1.cpp
#include ....
CDialog2 *ChildDialog = NULL; // the definition - solution found from the above links
void CDialog1::SomeFunction()
{
if (ChildDialog != NULL) // this line accessing the static member produces the error
{
// some code
}
}
即使定义了静态成员,编译后仍会显示未解决的编译错误外部符号。我还能缺少什么来解决此问题?