c++ - Smart unique pointer as a member variable -


this question has answer here:

i have class as:

class largeobject {   public:     largeobject();     void dosomething();   private:     std::unique_ptr<thing> pthing; }; 

then when want create pointer in constructor

largeobject() {   pthing(new thing()); //this not work. } 

i want use member variable throughout code. how that?

i think initialization should in constructor's initialization list, that's place constructors should invoked constructor:

largeobject() :pthing(new thing){} 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -