22 Jan
2007
22 Jan
'07
6:31 a.m.
On 1/22/07, ethann.castell@caliton.com
class A : public base_class
classA::Process() { boost::shared_ptr<A> ptr_a = shared_from_this(); // get pointer to myself
//afterwards - use_count = 2, weak_count = 2 ... if (some_condition){ boost::shared_ptr<B2> ptr_b2( ptr_a) ; // create new B2 and pass pointer to me. }else{ // crashes with bad_weak_ptr error on this line. } }
boost::shared_ptr<B2> ptr_b2( ptr_a) does not create a new object of B2. Do you mean ptr_b2(new B2(ptr_a))? Could you please post a more complete code sample (at least of Process)?