在C#我有以下的类,它编译就好:++实现的GetEnumerator用C
class CustomItem { }
class CustomList : IList<CustomItem>
{
public CustomItem this[int index]
{
get { return null; }
set { throw new NotImplementedException(); }
}
public void CopyTo(CustomItem[] array, int arrayIndex)
{
}
public int Count { get { return 10; } }
public int IndexOf(CustomItem item) { throw new NotImplementedException(); }
public void Insert(int index, CustomItem item) { throw new NotImplementedException(); }
public void RemoveAt(int index) { throw new NotImplementedException(); }
public void Add(CustomItem item) { throw new NotImplementedException(); }
public void Clear() { throw new NotImplementedException(); }
public bool Contains(CustomItem item) { throw new NotImplementedException(); }
public bool IsReadOnly { get { return true; } }
public bool Remove(CustomItem item) { throw new NotImplementedException(); }
public IEnumerator<CustomItem> GetEnumerator() { throw new NotImplementedException(); }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{ throw new NotImplementedException(); }
}
当我尝试在C相同++我得到几个编译器错误:
ref class CustomItemValue { };
typedef CustomItemValue^ CustomItem;
ref class CustomList : public IList<CustomItem>
{
public:
property CustomItem default[int]
{
virtual CustomItem get(int index) { return nullptr; }
virtual void set(int index, CustomItem value) {}
}
virtual void CopyTo(array<CustomItem>^ array, int arrayIndex)
{
}
property int Count { virtual int get() { return 10; } }
virtual int IndexOf(CustomItem item) { throw gcnew NotImplementedException(); }
virtual void Insert(int index, CustomItem item) { throw gcnew NotImplementedException(); }
virtual void RemoveAt(int index) { throw gcnew NotImplementedException(); }
virtual void Add(CustomItem item) { throw gcnew NotImplementedException(); }
virtual void Clear() { throw new NotImplementedException(); }
virtual bool Contains(CustomItem item) { throw gcnew NotImplementedException(); }
property bool IsReadOnly { virtual bool get() { return true; } }
virtual bool Remove(CustomItem item) { throw gcnew NotImplementedException(); }
virtual IEnumerator<CustomItem>^ GetEnumerator() { throw gcnew NotImplementedException(); }
virtual System::Collections::IEnumerator^ GetEnumerator()
{ throw gcnew NotImplementedException(); }
};
来自编译器的错误消息是:
.\mc.cpp(38) : error C2556: 'System::Collections::IEnumerator ^CustomList::GetEnumerator(void)' : overloaded function differs only by return type from 'System::Collections::Generic::IEnumerator ^CustomList::GetEnumerator(void)' with [ T=CustomItem ] .\mc.cpp(36) : see declaration of 'CustomList::GetEnumerator' .\mc.cpp(38) : error C2371: 'CustomList::GetEnumerator' : redefinition; different basic types .\mc.cpp(36) : see declaration of 'CustomList::GetEnumerator'
任何人都可以帮助我吗?
中找到更多关于显式覆盖的信息,我想知道您是否不能继承Collection,并且只是使用覆盖来替换您想要更改的特定方法? –
2009-05-04 07:46:12
对不起,但我没有在.NET中找到类Collection。据我所知名单或阵列存在,但这不完全是我想要的。感谢您的建议,但我需要这个来访问.NET中的现有列表实现。该列表是用C++实现的,我想访问它。 –
2009-05-04 08:12:25