Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2005-02-04 13:33:05


On Feb 4, 2005, at 4:22 AM, Oliver Kowalke wrote:

> Hi,
> is it possible to use boost::function as drop-in replacment for
> ordinary
> function pointers - or are there some other solutions?
> I can't get the code below to work.
> thx and best regards,
> Oliver
>
> typedef void (*FunctionPointer) ( int);
> [snip]

> class Test
> {
> public:
> void f( FunctionPointer fp)
> { fp( 1); }
> };
[snip]
> boost::function< void(int) > f;
[snip]
> // tst.f( my_fun); // works
> tst.f( f); // ??? - doesn't compile
> }

A boost::function object acts like a function pointer, but it is not a
function pointer. If you change the typedef of FunctionPointer to

   typedef boost::function<void(int)> FunctionPointer;

then the code will work.

        Doug


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