我想將c#代碼轉換爲C++/cli。一切順利,直到我開始將接口事件顯式實現轉換爲C++/cli語法。C++ cli接口事件顯式實現
讓我們在C#中說,我有這個接口
public interface Interface
{
public event MyEventHandler Event;
}
這是在類實現中明確的方式,因此它不會與它的名稱的另一個成員發生衝突:
public interface Class : Interface
{
event MyEventHandler Interface.Event;
public event AnotherEventHandler Event;
}
我試圖將Class轉換爲C++/cli,如下所示:
public ref class Class : public Interface
{
virtual event MyEventHandler^ Event2 = Interface::Event
{
}
...
};
這將不會編譯給我「... = Interface :: Event」部分的語法錯誤。有沒有人知道什麼是正確的語法,或者它甚至存在於C++/cli中?我花了一些時間在互聯網上搜索,但沒有遇到任何有用的東西。
UPDATE:下面是一個說明該問題的完整的C/CLI代碼:
public delegate void MyEventHandle();
public delegate void AnotherEventHandle();
public interface class Interface
{
event MyEventHandler^ Event;
};
public ref class Class : public Interface
{
public:
virtual event MyEventHandler^ Event2 = Interface::Event
{
virtual void add(MyEventHandle^) {}
virtual void remove(MyEventHandle^) {}
}
event AnotherEventHandler^ Event;
};
通過VC++ 2012輸出誤差爲「錯誤C2146:語法錯誤:缺少 ';'前標識「一個MyEventHandler」」
通常,當你得到了有關錯誤消息的問題,這是一個好主意,提供該問題的消息。 – 2013-03-14 09:03:00
這裏沒有用於測試的編譯器,但我希望該行讀取「虛擬事件EventHandle Interface :: Event」,而不需要其他名稱或分配。 – nvoigt 2013-03-14 09:03:25
更新後的帖子與錯誤信息 – edwabr123 2013-03-14 09:45:55