鱼C论坛

 找回密码
 立即注册
查看: 1566|回复: 1

[已解决]有关static的问题求解!!

[复制链接]
发表于 2015-10-8 11:27:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. class ConfigParser
  2. {
  3. private:
  4.         ConfigParser(void);
  5.         static ConfigParser* m_self; //自己的唯一地址
  6. public:
  7.        
  8.         //获得单例
  9.         static ConfigParser * instance()
  10.         {
  11.                 if (m_self == NULL)//问题出现在这里
  12.                 {
  13.                         m_self = new ConfigParser();
  14.                         /* code */
  15.                 }

  16.                 return m_self;
  17.         }
复制代码


用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都放在了一个文件夹中,在线求解答!!!
最佳答案
2015-10-8 18:22:07
你提供的代码有限,从你贴出来的代码看不出问题
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2015-10-8 18:22:07 | 显示全部楼层    本楼为最佳答案   
你提供的代码有限,从你贴出来的代码看不出问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-21 07:26

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表