$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Igor R (boost.lists_at_[hidden])
Date: 2008-07-16 13:13:07
> I don't need to do 'b= NULL' in A's constructor, right?
Right.
> But why this line won't compile "b = new B();" ?
The constructor you need for this conversion is declared as
"explicit". Do it this way:
typedef boost::shared_ptr<B> BPtr;
B& A::getB() {
if (!b)
b = BPtr(new B());
return *b; // btw, do you really wish to return the reference?
}