class App
{
public:
App();
static App* theApp;
};
App::App()
{
theApp=this;
}App* AfxGetApp()
{
return App::theApp;
}void main()
{
App MyObj;
}以上代码编译通过,但连接的时候,显示有两个错误∶
Lisi003.obj : error LNK2001: 外部シンボル ""public: static class App *  App::theApp" (?theApp@App@@2PAV1@A)" は未解決です
Debug/Lisi003.exe : fatal error LNK1120: 外部参照 1 が未解決です。
(我用的是日文版)什么原因呢?

解决方案 »

  1.   

    because you have used the static memeber theApp in no static function App and AfxGetApp, so you must define the function as static or define the member as nonstatic
      

  2.   

    class App
    {
    public:
    App();
    static App* theApp;
    };
    App* App::theApp=0;////////什么意思App::App()
    {
    theApp=this;
    }App* AfxGetApp()
    {
    return App::theApp;
    }void main()
    {
    App MyObj;
    }
      

  3.   

    一个类的静态成员变量必须初始化。
    static App::theApp = NULL;
      

  4.   

    theApp应该是系统变量,我不知道这变量能不能拿来用,试试用其它函数变量名
      

  5.   

    theApp应该声明,
    静态成员变量应该在成员函数中初始化.
    还有就是请抵制日货,打倒日本人