I am trying to use extern "C"
to be able to call a C++ class within a different C file. I can build this fine until I actually include the .h
in the C file I want to call the C++ class from.
MyClass.cpp
MyClass::MyClass(){};
MyClass::~MyClass(){};
extern "C" void* MyClassInit(){
return new MyClass();
}
MyClass.h
extern "C" void* MyClassInit();
OK - the above compiles. But now I want to use MyClassInit
in another .c
file. As soon as I
#include "MyClass.h"
in that file I get
error: expected identifier or '(' before string constant
in MyClass.h
where the externs are defined.
I assume I am missing some "if cplusplus" or another extern or something else very obscure.