请教关于接口和继承的问题?
我想实现一个接口 ICollection,此接口只定义一些通用的方法。
// 最底层基类class DIRECT_UI IObject{public: IObject(); virtual ~IObject();};/************* ICollection.h *************/// 定义接口class DIRECT_UI ICollection : public IObject{public: ICollection(); virtual ~ICollection();public: virtual int Add(IObject *pObject) = 0; virtual void Insert(int index, IObject *pObject) = 0; virtual void Remove(IObject *pObject) = 0; virtual void RemoveAt(int index) = 0; virtual void RemoveRange(int index, int count) = 0; virtual int IndexOf(IObject *pObject) = 0; virtual IObject* operator[](int index) = 0; virtual int Count() = 0; virtual void Clear() = 0; virtual void SetParent(IObject *pObject) = 0; virtual IObject* GetParent() = 0;};/************* UIElementCollection.h *************/// 接口的一个实现类 [IUIElement 派生于 IObject]class UIElementCollection : public ICollection{public: UIElementCollection(); ~UIElementCollection();public: virtual int Add(IUIElement *pUIElement); virtual void Insert(int index, IUIElement *pUIElement); virtual void Remove(IUIElement *pUIElement); virtual void RemoveAt(int index); virtual void RemoveRange(int index, int count); virtual int IndexOf(IUIElement *pUIElement); virtual IUIElement* operator[](int index); virtual int Count(); virtual void Clear(); virtual void SetParent(IUIElement *pParent); virtual IUIElement* GetParent();};编译错误:1>uielementcollection.h(42): error C2555: “UIElementCollection::operator []”: 重写虚函数返回类型有差异,且不是来自“ICollection::operator []”的协变1>icollection.h(30) : 参见“ICollection::operator []”的声明1>uielementcollection.h(42): error C2555: “UIElementCollection::GetParent”: 重写虚函数返回类型有差异,且不是来自“ICollection::GetParent”的协变1>icollection.h(36) : 参见“ICollection::GetParent”的声明