编译器错误 C3909

WinRT 或托管事件声明必须在 WinRT 或托管类型中发生

注解

Windows 运行时事件或托管事件是在本机类型中声明的。 要修复此错误,请在 Windows 运行时类型或托管类型中声明事件。

有关详细信息,请参阅事件

Example

以下示例生成 C3909,并演示如何修复它:

// C3909.cpp
// compile with: /clr /c
delegate void H();
class X {
   event H^ E;   // C3909 - use ref class X instead
};

ref class Y {
   static event H^ E {
      void add(H^) {}
      void remove( H^ h ) {}
      void raise( ) {}
   }
};