Recommended Posts

I was playing a little with the boost.bind library and I tried to bind a function member from one class (and the binding is also done in this class) to a member function (boost.function) from another class.
So I wrote quickly some small test code:
//session.h

Breakdown: bind() expects to handle the member function itself, so an intermediary functor like mem_fun isn't typically used, and if valid, only serves to limit your options. Since it is a member function, the first, implicit "this" argument must be passed. Then there's the first explicit argument, the integer. _1 is a lambada placeholder, meaning "put the first argument here". Thus, calling:

boost::bind( & session::execcommand , this , _1 )( 42 );

Is equivilant to:

this->*(&session::execcommand)( 42 );

Just to throw in another example, these would produce the same results: