是否可以在DLL中导出C链接的C ++成员方法?

在cpp文件中考虑这个:

struct someStruct{ public: extern "C" __declspec(dllexport) int sumup(); } someStruct; extern "C" __declspec(dllexport) int someStruct::sumup() { return 0; } 

这不编译: error: expected unqualified-id before string constant是否无法使用C链接导出C ++成员方法?

首先,链接规范不适用于成员函数; 通过[dcl.link] / 4:

[…]链接规范只应在命名空间范围内发生(3.3)。 […]

但是在标准中甚至有一个例子与你的问题有关,在同一段中:

[…]在确定类成员名称和类成员函数的函数类型的语言链接时,忽略AC语言链接。 [ 例如:

 extern "C" typedef void FUNC_c(); class C { void mf1(FUNC_c*); // the name of the function mf1 and the member // function's type have C ++ language linkage; the // parameter has type pointer to C function FUNC_c mf2; // the name of the function mf2 and the member // function's type have C ++ language linkage static FUNC_c* q; // the name of the data member q has C ++ language // linkage and the data member's type is pointer to // C function }; extern "C" { class X { void mf(); // the name of the function mf and the member // function's type have C ++ language linkage void mf2(void(*)()); // the name of the function mf2 has C ++ language // linkage; the parameter has type pointer to // C function } }; 

结束例子 ]

不,它没有那种方式。 它根本不起作用。 做不到。 没有办法没办法。