Friday, 15 April 2011

how to specify a c++ function pointer that may accept boost::bind'ed functions -



how to specify a c++ function pointer that may accept boost::bind'ed functions -

i trying store list of arbitrary callback functions using boost::bind allow arguments specific callback:

eg:

void callback1(int something) {...} void callback2(int onething,theotherthing) {...}

the callback scheme stores these in container:

typedef void (*lpvfunc)(); // ... std::map <int,lpvfunc>regged_callbacks;

and @ point registration function:

registercallback(int slot,lpvfunc cb) { regged_callbacks[slot]=cb; }

the problem occurs when seek bind adapt callback

registercallback(1,boost::bind(callback2,42,31337));

and shazbang compiler errors like: ...note: no known conversion argument 2 'boost::_bi::bind_t > >' 'lpvfunc {aka void (*)()}'|

so prepare create work (since boost::asio seems able take things these fine in pointers callbacks)

you can't store raw function pointer functor has capture. instead store type-erased functors, without changing else:

typedef std::function<void()> lpvfunc;

(or boost.function if you're not on c++11)

c++ boost

No comments:

Post a Comment