First of all your invokeFunc
method does not need to use std::bind()
and should at least check if function is there:
void *invokeFunc(std::string const& name, void *arg)
{
auto &x = functionTable_[name];
if( !x ) return 0;
return x(arg);
}
But better would be to use std::map::find()
I believe
Second you can use std::bind()
to pass method:
Derived()
{
registerFunc("world", [this] (void *arg) { printf("world"); return nullptr; });
invokeFunc("world");
registerFunc("method", std::bind( &Derived::memberFunc, this, _1 ) ) );
invokeFunc("method");
}