I wrote a singleton class who return a smart pointer and i choose to use shared_ptr.
In main i have this error :
undefined reference to `Singleton_Share_ptr::instance
This is my code :
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;
}
Or have anyone any ideea what to write in my main ?