If I understand you correctly, you can do this in two different ways.
Assuming this callback structure uses the Data parameter so that you can pass your own data to the callback function (general paradigm), you can do it like this:
class MyProcessingClass { public: MyProcessingClass(); virtual ~MyProcessingClass(); // Do whatever processing in this method virtual void onReceive(Lacewing::Server &Server, Lacewing::Server::Client &Client); } void onReceive (Lacewing::Server &Server, Lacewing::Server::Client &Client, char * Data, int Size) { if ( Data != NULL ) { MyProcessingClass *handler = reinterpret_cast<MyProcessingClass *>(Data); handler->onReceive( Server, Client ); } }
Or, if the data pointer is what you need to handle instead of the "user data pointer", you probably have to use a singleton, some kind of global variable or the like. In my experience, this is a less common way to use callbacks, and hopefully this is not what you are dealing with.
MyProcessingClass g_Processor; MyProcessingClass *GetProcessor() { return &g_Processor; // or some other way of getting your instance } void onReceive (Lacewing::Server &Server, Lacewing::Server::Client &Client, char * Data, int Size) { MyProcessingClass *handler = GetProcessor(); if ( handler != NULL ) { handler->onReceive( Server, Client ); } }
source share