Boost logo

Boost Users :

Subject: Re: [Boost-users] boost shared_ptr with own dtor
From: Philipp Kraus (philipp.kraus_at_[hidden])
Date: 2012-12-08 12:24:08


On 2012-12-08 17:45:07 +0100, Andrew Holden said:

> Philipp Kraus <philipp.kraus_at_[hidden]> wrote:
> Hello,
>
> I'm using boost::shared_ptr for using a C pointer. The ctor and all
> functions are called without any problem, but I have got a problem with
> the dtor.
> I need to call a C function on the dtor eg
>
> cptr_close( mypointer )
>
> How can I this used with boost::shared_ptr? I need the cptr_close call
> on the pointer member of the dtor on the shared_ptr.
>
> Thanks a lot
>
> Phil
>
>
>
>
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> I would ini tialize the shared pointer like so:
>
> boost::shared_ptr <MyType> ptr;
>
> MyType *temp_ptr = cptr_open(); //Use a temporary pointer to avoid
> initializing the shared pointer with null.
>
> if (temp_ptr)
> ptr.reset(temp_ptr, &cptr_close);
> //Now discard temp_ptr
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

O
http://www.boost.org/doc/libs/1_52_0/libs/smart_ptr/shared_ptr.htm#constructors
I found that I can use a ctor with
template<class Y, class D> shared_ptr(Y * p, D d);
and D is a dtor call. Do you have an example for D ?

Thanks

Phil


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