我試圖在C++/CLI中實現一個抽象的C#類。這個抽象基類已經實現INotifyPropertyChanged的,並提到用C#編寫:C++/CLI:實現一個抽象的C#類,實現INotifyPropertyChanged結果在C++編譯器錯誤C3766
public abstract class BaseClass : INotifyPropertyChanged
在C++/CLI裝配,我確實有實現INotifyPropertyChanged另一個接口:
public interface class IAnotherNotifyPropertyChangedClass : public INotifyPropertyChanged
現在,繼承時抽象C#類BaseClass的貫徹IAnotherNotifyPropertyChangedClass在C++/CLI我得到如下:
public ref class AnotherNotifyPropertyChangedClass : public BaseClass, public IAnotherNotifyPropertyChangedClass
這就導致在下面的編譯錯誤:
error C3766: 'AnotherNotifyPropertyChangedClass' must provide an implementation for the interface method 'void System::ComponentModel::INotifyPropertyChanged::PropertyChanged::add(System::ComponentModel::PropertyChangedEventHandler ^)'
只要我刪除了INotifyPropertyChanged的從IAnotherNotifyPropertyChangedClass接口聲明,一切編譯罰款。這是爲什麼?這個聲明在使用C#時會很好地編譯。我使用VS 2012並編譯.NET 3.5混合模式程序集。
在此先感謝!
乾杯!
編輯: 類似的問題(沒有C#)在這裏:http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/3047b8d1-348c-4ca6-b3f3-c396c03fedf7/ 所以這是C++/CLI的設計?
用C#編寫的抽象類實現了接口。在純C#中執行相同的場景(聲明另一個繼承INotifyPropertyChanged並在基類頂部實現它的接口)就像一個魅力... – barnacleboy
我試圖說如果有兩個INotifyPropertyChanged的實現。這與公共IEnumerator GetEnumerator()和IEnumerable.GetEnumerator()類似,您需要兩者均可用。 –