问题描述
我写了一个单例类,该类返回一个智能指针,我选择使用shared_ptr。
undefined reference to `Singleton_Share_ptr::instance
这是我的代码:
class Singleton_Share_ptr
{
private :
Singleton_Share_ptr(){value =0;}
static std::shared_ptr<Singleton_Share_ptr> instance;
int value;
public :
Singleton_Share_ptr(const Singleton_Share_ptr&) = delete;
Singleton_Share_ptr & operator=(const Singleton_Share_ptr&) = delete;
~Singleton_Share_ptr() = default;
int getValue(){ return value;}
static std::shared_ptr<Singleton_Share_ptr> getInstance()
{
if(!instance)
{
instance = std:: shared_ptr<Singleton_Share_ptr>(new Singleton_Share_ptr());
}
return instance;
}
};
int main()
{
std::shared_ptr<Singleton_Share_ptr> s1(Singleton_Share_ptr::getInstance());
std::cout<<s1->getValue()<<std::endl;
return 0;
}
或者有人可以在我的主要内容中写些什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)