
Hi, In the following program... #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> class A {}; int main () { boost::shared_ptr<A> x; // A: bad_weak_ptr thrown // boost::shared_ptr<A> x ((A *) 0); // B: works boost::weak_ptr<A> y (x); boost::shared_ptr<A> z (y); } ... I observe that with line A included (but not line B), a bad_weak_ptr is thrown by the line which declares z. With line B included (but not line A), all is well.
From looking at the boost source, it seems that line A results in a shared_ptr to nothing (use_count() == 0), and line B results in a shared_ptr to 0 (use_count() == 1).
I can work around this, I'm sure. Can anyone clarify my muddled thinking and explain why boost is behaving correctly in this situation (if indeed it is!) Many thanks Carl