I use a third-party library that allows me to register callbacks for specific events. The register function looks something like this. It uses a callback signature.
typedef int (*Callback)(std::string);
void registerCallback(Callback pCallback) {
}
My problem is that I want to register a member function as a callback, something like this
struct MyStruct {
MyStruct();
int myCallback(std::string str);
};
MyStruct::MyStruct() {
registerCallback(&MyStruct::myCallback);
}
int MyStruct::myCallback(std::string str) {
return 0;
}
Of course, the compiler complains saying
error C2664: 'registerCallback': cannot convert parameter 1 from 'int (__thiscall MyStruct :: *) (std :: string)' to 'Callback'
I look at libraries like function and binding, but none of them seem to be able to do the trick. I searched all over Google for an answer, but I don’t even know what to call it, so it didn’t help much.
Thanks in advance.