我有一個A類,它實現一個接口ICLI/C++虛擬事件處理器
在界面I是聲明:
virtual event System::EventHandler ^eh;
在AI的頭文件中由similare聲明實現此:
virtual event System::EventHandler ^eh;
在AI的cpp文件
希望該事件的委託分配給anotheter變量:
EventHandler ^eh2 = eh;
這給了錯誤
Error 285 error C3918: usage requires 'eh' to be a data
我也嘗試
EventHandler^ eh2 = gcnew System::EventHandler(eh);
這給了錯誤:
Error 285 error C3924: error in argument #1 of delegate constructor call 'System::EventHandler':
你可以發佈你的整個接口和實現類聲明,以及你得到編譯錯誤的整個函數嗎?除此之外,你讀過這個嗎? http://msdn.microsoft.com/en-us/library/w901cc8a%28v=VS.100%29.aspx –
從接口的事件定義中刪除虛擬機時會發生什麼?只有實現類應該將事件定義爲虛擬的,而不是接口本身。 –
@Roger:有點不相關,但界面沒有定義,它只是聲明 –