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

2

10

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

Pooley answered 14/1, 2011 at 14:55 Comment(0)
P
25

Yes. you can use reset() member function.

class foo {
public:
    foo()
    {
         p.reset(new bar());
    }
private:
  boost::scoped_ptr<bar> p;
};
Puleo answered 14/1, 2011 at 14:59 Comment(1)
Is it possible to initialize it in the initialization list? If so, how?Denisse
B
6

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

Baiss answered 14/1, 2011 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.