This doesn't work because RawDataCB
is a member function not a global function. You can declare RawDataCB
as a static function in the class as follows and this will work. However you will no longer have access to the this
pointer (i.e. no member variables) unless you add it as a parameter to RawDataCB
and perhaps make RawDataCB
a friend to gain access to private data of the class as a member function would have. This can be done by updating the function declaration as follows:
class CETAPI {
static void RawDataCB(RawData& r, void* userData);
};
Alternatively, you can pass a pointer to RawDataCB
as a member function pointer rather than a function pointer. Member function pointers can be manipulated as follows, so you will just pass an object of type RawDataCBType
to SetRawDataCB
.
typedef void (CETAPI::*RawDataCBType)(RawData&, void*); // typedef the member function pointer type
RawDataCBType pmf = &CETAPI::RawDataCB; // create and initialize a pointer to the member function
pCETAPIObject->*pmf(r, userData); // call the member function on an object of type CETAPI
Here is a good article that talks about member pointers.