I am using a C library in a C++ application. The C SDK has functions that take a callback function pointer as an argument. The signature of these functions is usually like:
typedef int (* Func) (type1 c, type2 d);
I have my code structured using classes in C++. However, I can't pass any member functions to this function as callback because it doesn't accept int (MyClass::*)(type1 c, type2 d)
and only accepts int (*)(type1 c, type2 d)
.
I'm getting around this by defining all my callbacks as static
in the various classes and then passing them to the C library which then works.
I am still new to C++ so I'm not sure if this is the right solution? The code works, but I'd love to hear if I'm doing this wrong.