Can shared_ptr release ownership of a pointer without destroy it?
As following manner: shared_ptr<Foo> ptr(new Foo()); ... Foo * p = ptr.release(); -- /*******************/ ×ÔÓÉ£šliberty£©ÎÞ·ÇŸÍÊÇÕâÑùÒ»ÖÖ³Ðŵ£ºÃ¿žöÈËœ«»áµÃµœÒ»ÖÖ±£ÕÏ£¬±£ÕÏÎÒÃÇ¿ÉÒÔÓë ÈšÍþ¡¢¶àÊý¡¢Á÷Ë׌°ÓßÂÛµÄÓ°ÏìÏ࿹ºâ¡£ /*******************/
Black Ice wrote:
As following manner:
shared_ptr<Foo> ptr(new Foo()); ... Foo * p = ptr.release();
No, it cannot. If you want to release ownership, use auto_ptr. In general, you can't destroy the shared_ptr pointer yourself, since you don't know how the shared_ptr has been created.
--- At Mon, 10 Feb 2003 15:20:57 +0200, Peter Dimov wrote:
Black Ice wrote:
As following manner:
shared_ptr<Foo> ptr(new Foo()); ... Foo * p = ptr.release();
No, it cannot. If you want to release ownership, use auto_ptr. In general, you can't destroy the shared_ptr pointer yourself, since you don't know how the shared_ptr has been created.
It seems then that Boost might benefit from an extended auto_ptr implementation. shared_ptr and friends provide for alternative delete functions where as auto_ptr does not. ...Duane
participants (4)
-
Black Ice
-
dlux42 <dlux@spam.sch.bme.hu>
-
Duane Murphy
-
Peter Dimov