Boost logo

Boost Users :

From: Meryl Silverburgh (silverburgh.meryl_at_[hidden])
Date: 2008-07-16 12:43:36


Hi,

I have a class like this:

class A {
 private:
    B* b;
  public:
    A();
    B& getB();
}

A::A() {
   b = NULL;
}

B& A::getB() {
   if (b == NULL) {
       b = new B();
   }

  return *b;
}

when I switch to use boost shared_ptr, i.e. switch from 'B* b' to
'shared_ptr<B> b' in A's class definition.

I don't need to do 'b= NULL' in A's constructor, right?

But why this line won't compile "b = new B();" ?

I get this error:

A.cpp:297: error: no match for 'operator=' in '((const
A*)this)->A::xBlockMap = (((B*)operator new(128u)),
(<anonymous>->B::B(((const A&)((const A*)this)), ((int)strict)),
<anonymous>))'
/usr/local/include/boost-1_35/boost/shared_ptr.hpp:194: note:
candidates are: boost::shared_ptr<T>&
boost::shared_ptr<T>::operator=(const boost::shared_ptr<T>&) [with T =
B]

Thank you for any help.


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