
6 May
2010
6 May
'10
8:49 p.m.
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