I'm trying to understand what's going on in the following code. When object-a is deleted, does it's shared_ptr member variable object-b remains in memory because object-c holds a shared_ptr to object-b?
class B
{
public:
B(int val)
{
_val = val;
}
int _val;
};
class A
{
public:
A()
{
_b = new B(121);
}
boost::shared_ptr<B> _b;
};
class C
{
public:
C()
{
}
void setRef( boost::shared_ptr<B> b)
{
_b = b;
}
boost::shared_ptr<B> _b;
};
int main()
{
C c;
{
A *a = new A();
cout << "a._b.use_count: " << a->_b.use_count() << endl;
c.setRef(a->_b);
cout << "a._b.use_count: " << a->_b.use_count() << endl;
delete a;
}
cout << c._b->_val << endl;
}