【发布时间】:2013-11-04 14:16:41
【问题描述】:
我有一个类 Foo,它有一个公共事件 Bar。我需要清除对 Bar 的所有订阅。
在 C# 中就像(在 Foo 类中)一样简单:
public void RemoveSubscribers() { this.Bar = null; }
(另见this问题)
如何在 C++/CLI 中执行此操作?我无法将 Bar 设置为 nullptr:编译器吐出错误
Usage requires 'Foo::Bar' to be a data member
我查看了 Bar 的 RemoveAll 方法,但我不明白我应该提供什么作为参数...
编辑 1: 为清楚起见,Bar 声明如下:
public ref class Foo
{
public:
event MyEventHandler^ Bar;
};
【问题讨论】:
-
好吧,你是如何声明 Bar 的?
-
@Yochai Timmer 为了清楚起见,我编辑了我的问题。