Boost logo

Boost Users :

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?
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net