|
Boost Users : |
Subject: [Boost-users] [shared_ptr] Is there an interface to set the ptr a shared_ptr holds
From: Max (loadcom_at_[hidden])
Date: 2008-12-28 22:29:27
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/ )
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net