Can a class member of type boost::scoped_ptr
be initialized inside the class' constructor? How?
(Not in the initialization list)
Asked
Active
Viewed 5,433 times
10

Jonathan Livni
- 101,334
- 104
- 266
- 359
2 Answers
25
Yes. you can use reset() member function.
class foo {
public:
foo()
{
p.reset(new bar());
}
private:
boost::scoped_ptr<bar> p;
};

Artyom
- 31,019
- 21
- 127
- 215
-
1Is it possible to initialize it in the initialization list? If so, how? – User Oct 17 '11 at 20:39
6
scoped_ptr has a method scoped_ptr<T>::reset(T * p=0)
which you can call in your enclosing class's constructor.

Michael Cornelius
- 1,516
- 1
- 11
- 11