[shared_ptr] Is there an interface to set the ptr a shared_ptr holds

Hello, I have the following code scenario: A *pa = NULL; // pa will be allocated here (by 3rd-party function) // by setA(), // whose behavior could not be changed setA(pa); // prototype: void setA(A*& pa) //... pa->close(); I want to apply shared_ptr to make it easier to maintain, or, more specifically here, to save a close() call. new version: boost::shared_ptr<A> pa(NULL, boost::bind(&A::close, _1)); setA(pa.get()); // because get() returns T* instead of T*&, // this line chokes the compiler //pa->close(); not needed any more Is there any way to get my goal accomplished? Thanks for any help. B/Rgds Max ------------------------------------------------------------------- 新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )

On Sun, Dec 28, 2008 at 22:29, Max
I have the following code scenario:
A *pa = NULL;
// pa will be allocated here (by 3rd-party function) // by setA(), // whose behavior could not be changed setA(pa); // prototype: void setA(A*& pa)
//...
pa->close();
I think the following is fine: A *pa_ = 0; setA(pa_); boost::shared_ptr<A> pa(pa_, boost::bind(&A::close, _1)); Since the shared_ptr constructor will call the deleter if its internal allocation fails. ~ Scott
participants (2)
-
Max
-
Scott McMurray