You could store std::function<void()>
in the class where you register the callbacks, and then add a function template register
member function:
struct Foo
{
template <typename F>
void register(EventType type, F&& fun)
{
// make an std::function<void()> from fun and store
}
};
Then, you do the binding of Class
instance and Class
member function on the caller's side.
struct Bar { void bar() {} };
void foobar() { std::cout << "foobar!\n"; }
Foo f;
Bar b;
f.register(event1, std::bind(&Bar::bar, b)); // will call b.bar()
f.register(event2, foobar); // will call foobar()