qw4749105 发表于 2015-10-8 11:27:37

有关static的问题求解!!


class ConfigParser
{
private:
        ConfigParser(void);
        static ConfigParser* m_self; //自己的唯一地址
public:
       
        //获得单例
        static ConfigParser * instance()
        {
                if (m_self == NULL)//问题出现在这里
                {
                        m_self = new ConfigParser();
                        /* code */
                }

                return m_self;
        }


用g++编译的时候总是提示我
confparser.h:23: undefined reference to `ConfigParser::m_self'
confparser.h:25: undefined reference to `ConfigParser::ConfigParser()'
confparser.h:25: undefined reference to `ConfigParser::m_self'
confparser.h:29: undefined reference to `ConfigParser::m_self'

问题是我在VS上面测试通过了,但是在g++上面就出现这种问题,请问是哪里有问题了,.h和.cpp都放在了一个文件夹中,在线求解答!!!

andalousie 发表于 2015-10-8 18:22:07

你提供的代码有限,从你贴出来的代码看不出问题
页: [1]
查看完整版本: 有关static的问题求解!!