Jonathan Livni
Jonathan Livni

Reputation: 107092

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)

Upvotes: 10

Views: 5448

Answers (2)

Michael Cornelius
Michael Cornelius

Reputation: 1564

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

Upvotes: 6

Artyom
Artyom

Reputation: 31233

Yes. you can use reset() member function.

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

Upvotes: 25

Related Questions