您好,我正在尝试在我的托管 C++ dll 中实现 C# 接口,如下所示:
public ref class MyClass : public IMyInterface
{
// Inherited via IMyInterface
virtual event EventHandler<MyEventArgs ^> ^ MyLoadedEvent;
public:
virtual event EventHandler<MyEventArgs ^> MyLoadedEvent
{
void add(MyEventArgs ^ f)
{
// some magic
}
void remove(MyEventArgs ^ f)
{
// some magic
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我不断收到两个错误:
1) 事件类型必须是句柄到委托类型
2) 类未能实现在...dll 中声明的接口成员函数“MyLoadedEvent::add”
我在实现中缺少什么或者实现接口事件的正确方法是什么?
谢谢!