所以我试试这段代码:
#ifndef TRANSMITTER_H
#define TRANSMITTER_H
class connector
{
public:
static boost::shared_ptr<connector> Instance(){
if(!instance)
{
instance = boost::shared_ptr<connector>(new connector());
}
return instance;
}
private:
connector(){}
static boost::shared_ptr<connector> instance;
};
#endif //TRANSMITTER_H
但得到链接错误:
Error 3 error LNK2001: unresolved external symbol "private: static class boost::shared_ptr<class connector> connector::instance" (?instance@connector@@0V?$shared_ptr@Vconnector@@@boost@@A)
我想返回的 shared_ptr 有什么问题?我应该将其设为函数范围静态变量吗?