$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] shared_ptr usage
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-05-06 16:49:47
AMDG
Hicham Mouline wrote:
> I have a class that stores a private member a shared_ptr<T> that points to a
> dynamically allocated instance of T.
>
> A getter member function returns T&.
>
>
>
> I now realise that in a snippet, I would like to store a new shared_ptr<T>
> to that returned object.
>
> T& t = myinstance.getT();
>
> I would like to store t in a shared_ptr, ie increment the count of shared
> pointers
>
> Do I do:
>
> shared_ptr<T> desiredPointer( &t );
>
>
>
> will this increment the count of shared pointers to t?
>
You have to use enable_shared_from_this
http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
In Christ,
Steven Watanabe