mercredi 1 juillet 2015

I was working with singleton pattern and shared_ptr.I was trying to make the code like this:

class A{
    private:
        static std::shared_ptr<A> instance;
        A();
    public:
        static std::shared_ptr<A> creatInstance();
};

std::shared_ptr<A> A::creatInstance(){
    if(!instance){
        instance=std::make_shared<A>();
    }
    return instance;
}

But I got a compiler error. Any thoughts? I tried to make make_shared be a friend function of class A,but it didn't work.

friend shared_ptr<A> make_shared<A>();

Aucun commentaire:

Enregistrer un commentaire