Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-03-25 06:16:52


From: "E. Gladyshev" <egladysh_at_[hidden]>
> > The latest version of boost::shared_ptr can handle
> > this. When you
> > construct a shared_ptr, you can pass in a function
> > that is used to
> > destroy the object instead of the default "delete".
> > Here's one way to do
> > it.
> >
> > #include <boost/shared_ptr.hpp>
> > void do_nothing(int*) { }
> > int g_x;
> > int main()
> > {
> > boost::shared_ptr<int> tmp(&g_x,
> > do_nothing);
> > }
>
> No, I don't think your suggestion will work
> with my example because foo() will have to
> know to use do_nothing() as well, but
> it has not idea what deleter to use.

Yes it will. foo() doesn't need to know anything about the deleter, as long
as it takes a shared_ptr.

> Just try it for yourself and remember
> we are looking for a generic solution.

Good advice. Follow it. :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk