I'm using a C library into a C++ project. This library allow me to register a C callback and in this callback I should call a C++ method of an object.
The situation is this:
myclass.h
class myclass
{
public:
myclass();
void callme();
};
extern "C"
{
void init():
int callback(int,int);
}
myclass.cpp
myclass::myclass()
{
init();
}
void myclass::callme()
{
cout<<"Ok\n";
}
extern "C"
{
void init()
{
//code
setlibraryCallback(callback);
//code
}
int callback(/*some arguments that I can't change*/ int a, int b)
{
//I should call "callme()" methos of my c++ object
}
}
Can I call a C++ method from this C callback? If yes how can I do? Thanks
EDIT: I found this similar question How to call a C++ method from C? However I cant pass the object as void pointer to the C callback because I can't change the callback arguments.