16 Jul
2008
16 Jul
'08
5:13 p.m.
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? }