131. Ownership

Question.5

Two objects reference each other with shared_ptr:

struct A { std::shared_ptr<B> b; };
struct B { std::shared_ptr<A> a; };

auto pa = std::make_shared<A>();
auto pb = std::make_shared<B>();
pa->b = pb;
pb->a = pa;
// pa and pb go out of scope

What happens?

Need Help? Refer to the Quick Guide below

Select Answer