VC.net继承IEnumerator接口的问题
有如下代码:
在标记1处的Current是不符合接口定义的,需要定义泛型的Current属性。
但是两个Current不能同时定义,怎么办?
VC.Net的显式重写并不能解决属性的问题,那该如何实现这个自定义的Class?
ref class Enumerator : System::Collections::Generic::IEnumerator<ItemType>, System::IDisposable
{
private:
ItemCollection<ItemType>^ m_List;
System::Int32 m_Index;
System::Int32 m_Version;
ItemType m_Current;
public:
Enumerator(ItemCollection<ItemType>^ list)
{
this->m_List=list;
this->m_Index=0;
this->m_Version=list->m_Version;
this->m_Current=ItemType();
}
virtual System::Boolean MoveNext()
{
ItemCollection<ItemType>^ list = this->m_List;
if ((this->m_Version == list->m_Version) && (this->m_Index < list->m_Size))
{
this->m_Current = list->m_InnerArray[this->m_Index];
this->m_Index++;
return true;
}
if (this->m_Version != list->m_Version)
{
throw gcnew System::InvalidOperationException("集合已改变,操作无效");
}
this->m_Index = this->m_List->m_Size + 1;
this->m_Current = ItemType();
return false;
}
//1
property virtual System::Object^ Current
{
System::Object^ get(){return this->m_Current;}
}
property virtual ItemType Current
{
ItemType get()
{
return this->m_Current;
}
}
virtual void Reset()
{
this->m_Index = 0;
this->m_Current = ItemType();
}
~Enumerator()
{
}
在标记1处的Current是不符合接口定义的,需要定义泛型的Current属性。
property virtual ItemType Current
{
ItemType get(){return this->m_Current;}
}
但是两个Current不能同时定义,怎么办?
VC.Net的显式重写并不能解决属性的问题,那该如何实现这个自定义的Class?
...全文


VC.NET

