boost::function is a template class, that takes a function signature. You can also use function0, function1, etc.
boost::function< void(uint32_t) >
defines a "callable" that looks like a function, i.e. it takes a single parameter of type uint32_t
and returns void.
The appropriate numbered template is function1< void, uint32_t >
. These always indicate the return type first, then the parameters in order.
boost::bind
is a very special function that deduces the arguments you pass into it and creates a functor for you.
It will not create a void(uint32_t) for you, it will create something that has the pattern of one.
Therefore change your signature to:
void f2(boost::function<void(uint32_t)>);
Then you can call it like this:
f2( boost::bind( &Test::f3, this, _1 ) );
Note the strange _1 is a "placeholder" telling boost::bind where it needs to put in the parameter, in this case the uint32_t
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…