A C++ member function has as its first parameter the this-pointer.
boost::bind makes a function-object form a function pointer and its passed parameter. The _1, _2 ... are place-holder (lambdas). They will be passed when the function-object is called.
class MyClass{
/// Callback signature for calling the function for a specific command.
typedef boost::function<void ()> TMenuCmdCallback;
int doFunction1(bool);
void doFunction2();
double doFunction3(int);
void setupMenu(){
TMenuCmdCallback callback;
m_Callbacks[ 1] = boost::bind(&MyClass::doFunction1, this, true); // allways pass true
m_Callbacks[10] = boost::bind(&MyClass::doFunction1, this, false); // allways pass false
m_Callbacks[ 2] = boost::bind(&MyClass::doFunction2, this);
m_Callbacks[ 3] = boost::bind(&MyClass::doFunction3, this, this->m_Int);
}
void callFunction(int index)
{
m_Callbacks[index]();
}
std::map<int, TMenuCmdCallback> m_Callbacks;
int m_Int;
};
In my example I do not check if the index is out of bounds. In this example also I don't need the lambdas because at run time (in callFunction) I have no parameters to pass.
I'm not sure if the the callback to the function3 really works (but it compiles at least).