Im trying to create a signal handling class with a Qt inspired interface like this
class MessageConsumer {};
class MessageHandler {
public:
static int Connect(int, MessageConsumer* obj, std::function handler) {
// Add callback to handler
}
};
class A : public MessageConsumer {
public:
void handleIt(void) {
// Do stuff
}
};
int main(void) {
A a;
MessageHandler::Connect(1, &a, &A::handleIt);
return 0;
}
But keep getting the compiler error
main.cpp: In function ”int main()”:
main.cpp:71:46: error: no matching function ”MessageHandler::Connect(int, A*, void (A::)())”
MessageHandler::Connect(1, &a, &A::handleIt);
^
main.cpp:53:5: anm: candidate: static int MessageHandler::Connect(int, MessageConsumer, std::function)
int MessageHandler::Connect(int, MessageConsumer* obj, std::function handler) {
^~~~~~~~~~~~~~
main.cpp:53:5: anm: no known conversion for argument 3 from ”void (A::*)()” to ”std::function”
Is there a way to solve this error without defining templates, i do not want use templating in the interface, i.e.
MessageHandler::Connect(1, &a, &A::handleIt)
No comments:
Post a Comment