Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-08-24 08:20:36


Vladimir Prus wrote:
> I wonder if shared_ptr can hold a pointer to a function.

Yes, it can.

> I've just tried the following program:
>
> #include <boost/shared_ptr.hpp>
> using namespace boost;
>
> int main()
> {
> extern int* object;
> boost::shared_ptr<int> p(object);
>
> extern void (*function)();
> boost::shared_ptr<void ()> p2(function);
>
> return 0;
> }
>
> The first initialization, of course, work. The second produces a lots
> of errors. Do I miss something obvious?

"Requires: the expression 'delete p' shall be well-formed and its behavior
defined."

Try a null deleter.


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