Member function callback
Present is a class to register functions as callbacks.
class Action {
private:
static std::multimap<std::string, std::function<void()>> actions;
public:
static void registerAction(const std::string &key,
std::function<void()> action);
}
Obviously it can not register member functions, as function pointer
objects to member functions require the class to be specified, but every
class should be able to register their functions.
std::function<void(Class&)>
Using a template system, I couldn't access all actions from one "instance"
of the static class I suppose. How could this be realized?
Example how it should look like:
class B {
public:
B() {
Action::registerAction("some_action", &callMe);
}
void callMe(){}
}
No comments:
Post a Comment