I'm trying to register functions for getting called back by an event handler, but I don't know how to pass methods of object which holds the callees to the event handler. I want to make the type which holds the callee independent, so that it could be a button object or a window e.g.
main.cpp: In function 'int main()':
main.cpp:36:44: error: invalid use of non-static member function 'void Callee::calledFunction(const string&)'
eventHandler.add(callee.calledFunction );
^
main.cpp:7:10: note: declared here
void calledFunction(const std::string& event) { std::cout << event; }
^~~~~~~~~~~~~~
Since you want to store a pointer to a member function, it seems you need an instance of that class to invoke it against.
Perhaps things could become easier using std::function or std::invoke() or other facilities from the <functional> header.
In function 'int main()': 38:56: error: invalid use of non-static member function
If your code beside this would work, I contemplate deriving from Callee for all classes which would register a method to the event handler. Would this be a current method?
@Enoizat: Thanks, your example works now.
@JLBorges: Thank you for this great example how using the functional facilities. I will reading up deeper at this topic.