编译器错误 C3387

“member”:__declspec(dllexport)/__declspec(dllimport) 不能应用于托管或 WinRT 类型的成员

dllimportdllexport__declspec 修饰符在托管或 Windows 运行时类型的成员上都无效。

下面的示例将生成 C3387,并演示如何修复此错误:

// C3387a.cpp
// compile with: /clr /c
ref class X2 {
   void __declspec(dllexport) mf() {   // C3387
   // try the following line instead
   // void mf() {
   }
};