开发者

C++: Can boost::scoped_ptr be initialized inside a constructor?

开发者 https://www.devze.com 2023-02-04 01:18 出处:网络
Can a class member of typ开发者_C百科e boost::scoped_ptr be initialized inside the class\' constructor? How?

Can a class member of typ开发者_C百科e boost::scoped_ptr be initialized inside the class' constructor? How?

(Not in the initialization list)


Yes. you can use reset() member function.

class foo {
public:
    foo()
    {
         p.reset(new bar());
    }
private:
  boost::scoped_ptr<bar> p;
};


scoped_ptr has a method scoped_ptr<T>::reset(T * p=0) which you can call in your enclosing class's constructor.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号