
4 Feb
2005
4 Feb
'05
11:33 a.m.
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