双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

VC.net继承IEnumerator接口的问题

北京的雾霾天 北京的雾霾天 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有如下代码:
		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?
...全文
评论 5
收藏 已收藏
分享
返回顶部
北京的雾霾天
VC.NET 7,538 成员 27,670 内容