Philipp Kraus <philipp.kraus@flashpixx.de> 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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

I would initialize 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