meessen
asked on
C++ object method called from C
I have to mix up C library functions and C++ objects.
At some point I wish that a C function calls a C++ method.
The problem is that the C functions is called from a .c compiled file.
This is an example of the cf function called from a function defined in a .c file.
cf( void* p ){
((Class*)p)->method();
}
Apparently it is possible to call C functions from C++ but not the reverse.
Any help would be warmly welcomed.
At some point I wish that a C function calls a C++ method.
The problem is that the C functions is called from a .c compiled file.
This is an example of the cf function called from a function defined in a .c file.
cf( void* p ){
((Class*)p)->method();
}
Apparently it is possible to call C functions from C++ but not the reverse.
Any help would be warmly welcomed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
extern "C" only defines how external parameters and return values are passed through, and how exported functions are named (the latter is different between C and C++)
Nevertheless, your extern "C" function is still C++ because it is defined in a CPP file.
Nevertheless, your extern "C" function is still C++ because it is defined in a CPP file.
ASKER
You gave the right answer.
I thought that using extern "C" would disallow to use method calls from within the encapsulated function. But apparently not. My test work.
Enjoy the points and the grade ;-)