Boost logo

Boost Users :

Subject: Re: [Boost-users] How & when to use weak_ptr
From: doug livesey (biot023_at_[hidden])
Date: 2011-07-03 06:52:10


That further simplifies everything, thankyou! :)

On 2 July 2011 20:29, Igor R <boost.lists_at_[hidden]> wrote:

> > Hmm -- so I guess, in the cases I'm talking about, I should store a
> > shared_ptr, and just return a const refererence.
>
> Note that it might be rather dangerous, if your caller would store
> such a const reference.
>
>
> > Then, if I need to have a copy of the member elsewhere to manipulate, I
> > could return a weak_ptr.
>
> Returning weak_ptr usually doesn't make sense (except for the case
> where you return it for tracking only). Note that shared_ptr is
> implicitly convertible to weak_ptr, so typically you return
> shared_ptr, and let the caller to decide what to do with it: if the
> caller indends to store it, but doesn't want strong referencing, it
> stores it as weak_ptr.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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