
On Thu, Dec 25, 2008 at 4:57 AM, Max
Suppose I have a shared_ptr which is the only owner of the pointee. I hope there is a way to hand over its ownership to another object without rendering the pointee being deleted.
Or, if the answer is no, is there an alternative class that has this feature?
The use case is like this:
B b; { shared_ptr p1(A()), p2(A());
b.GetOwnership(p1.HandOver()); // now p1 is empty }
That's not possible because in general shared_ptr can use custom deleters and/or aliasing which B can't deal with, unless it's shared_ptr itself. :) Consider: boost::shared_ptr<FILE> open_file( char const * name, char const * mode ) { if( FILE * f=fopen(name,mode) ) return boost::shared_ptr<FILE>(f,fclose); else boost::throw_exception(file_open_error()); } Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode