首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

代码,编译出错。求帮忙~解决办法

2012-05-29 
代码,编译出错。求帮忙~C/C++ code#include stdlib.h#include stdio.hclass SignalIns{public:static S

代码,编译出错。求帮忙~

C/C++ code
#include "stdlib.h"#include "stdio.h"class SignalIns{public:    static SignalIns& GetIns(void)    {        if ( Instance == NULL )        {            Instance = new SignalIns;        }        return *Instance;    }    void PrintString()    {        printf("Ins Test!\n");    }    static void DelIns(void)    {        delete Instance;        Instance = NULL;    }    ~SignalIns()    {            }protected:    SignalIns()    {    }private:    static SignalIns* Instance;};int main(int argc, char** argv){    SignalIns::GetIns();    SignalIns::DelIns();    system("pause");    return 0;}//main.obj : error LNK2001: 无法解析的外部符号 "private: static class SignalIns * SignalIns::Instance" (?Instance@SignalIns@@0PAV1@A)


不知道为什么会出现一个“无法解析的外部符号 ”,这个错误!

[解决办法]
静态变量需要在类外部进行定义。在类的外面可以
SignalIns* SignalIns::Instance=NULL;

热点排行