boost::shared_ptr cycle break with weak_ptr
问题 I am currently in a situation like: struct A { shared_ptr<B> b; }; struct B { shared_ptr<A> a; }; //... shared_ptr<A> a(new A()); shared_ptr<B> b(new B()); a->b(b); b->a(a); I know this won't work, because the references would continue to point to each other. I've also been told that weak_ptr solves this issue. However, weak_ptr has no get or -> overload. I've heard mentions of 'use lock() ', but can anyone give code examples of how to do this correctly? 回答1: Come on now. http://boost.org/doc