$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [shared_ptr] Is there an interface to set the ptr a shared_ptr holds
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-12-28 22: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