Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Can a class member of type boost::scoped_ptr be initialized inside the class' constructor? How?
(Not in the initialization list)

like image 888
Jonathan Livni Avatar asked Jan 14 '11 14:01

Jonathan Livni


2 Answers

Yes. you can use reset() member function.

class foo {
public:
    foo()
    {
         p.reset(new bar());
    }
private:
  boost::scoped_ptr<bar> p;
};
like image 179
Artyom Avatar answered Oct 15 '22 12:10

Artyom


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

like image 30
Michael Cornelius Avatar answered Oct 15 '22 12:10

Michael Cornelius