有什么方法可以从C代码调用C++代码吗?
class a
{
someFunction();
};
Run Code Online (Sandbox Code Playgroud)
如何someFunction()从C代码调用?换句话说,我在这里问如何避免名称损坏.
JUS*_*ION 13
(我不记得C++的所有该死的强制转换操作符并且懒得查找它,所以如果您喜欢以下代码,请用更具体的转换替换(Foo*).)
// My header file for the C API.
extern "C"
{
void bar(void* fooInstance);
}
// My source file for the C API.
void bar(void* fooInstance)
{
Foo* inst = (Foo*) fooInstance;
inst->bar();
}
Run Code Online (Sandbox Code Playgroud)