I have class which handles packages:
typedef void (*FCPackageHandlerFunction)(FCPackage*);
class FCPackageHandlers{
...
void registerHandler(FCPackage::Type type, FCPackageHandlerFunction handler);
void handle(FCPackage* package);
...
QHash<FCPackage::Type, FCPackageHandlerFunction> _handlers;
};
Then I have a server class who receive packages. Now I want to register a function who handles the packages. But this function must have a instance of the server for other variables.
So i try this:
struct FCLoginHandler{
FCServer* server;
FCLoginHandler(FCServer* server){
this->server = server;
}
void operator()(FCPackage* package){
std::cout << "Received package: " << package->toString().data() << "\n";
}
};
...
FCServer::FCServer(){
_handlers.registerHandle(FCPackage::Login, FCLoginHandler(this));
}
But then I get this error:
error: no matching function for call to 'FCPackageHandlers::registerHandler(FCPackage::Type, FCLoginHandler)'
note: candidates are: void FCPackageHandlers::registerHandler(FCPackage::Type, void (*)(FCPackage*))
Does anybody know the right solution?