|
Boost Users : |
Subject: Re: [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 23:04:28
Hello Scott£¬
Thanks.
It seems to be one of the simplest way to get to my needs
to declare another companion auto_free_helper.
It's better than none, if not the best.
I'm using this technique for stream:
std::ofstream outstream(strPath);
boost::shared_ptr<std::ofstream> os_auto_closer(&outstream,
boost::bind(&std::ofstream::close, _1));
B/Rgds
Max
----- Original Message -----
From: Scott McMurray <me22.ca+boost_at_[hidden]>
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [shared_ptr] Is there an interface to set the ptr a shared_ptr holds
Date: 2008-12-29 11:35:53
On Sun, Dec 28, 2008 at 22:29, Max <loadcom_at_[hidden]> wrote:
>
> 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
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
-------------------------------------------------------------------
ÐÂÀ˿ռ䡪¡ªÓëÅóÓÑ¿ªÐÄ·ÖÏíÍøÂçÐÂÉú»î£¡(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