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
Post a Comment