Boost logo

Boost Users :

Subject: Re: [Boost-users] [smart_ptr] weak_ptr / shared_ptr interaction
From: Kim Barrett (kab.conundrums_at_[hidden])
Date: 2009-07-03 12:01:11


At 1:55 PM +0200 7/3/09, Alexander Heinrich wrote:
>Now I experienced some odd behavior with the following piece of code:
><code>
>boost::shared_ptr<int> s1(new int(42)); // use_count == 1
>boost::weak_ptr<int> w(s1); // use_count == 1
>boost::shared_ptr<int> s2(w); // use_count == 2 (expected use_count == 1)

Both s1 and s2 should now have use_count of 2 at this point, since there
are 2 shared_ptrs sharing ownership of the same pointee.

The post-condition expression is correct; the value of r.use_count()
was changed by the construction of the new shared_ptr.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net