VC6.0容器的迭代器初始化存在问题

demystify demystify 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
使用C c(b,e) 创建c,其元素是迭代器b和e标识的范围的元素副本。 适用于所有容器
描述:
void f()
{
vector<int> m_vector;
list<int> m_list;
for(int i=0; i<10; i++)
{
m_vector.push_back(i);
m_list.push_back(i);
}
vector<int> m_TempVector(m_list.begin(), m_list.end());
cout<<"比较大小:"<<endl;
if(m_TempVector == m_vector)
cout<<"list与vector大小相等。"<<endl;
else
cout<<"不等"<<endl;
return;
}
这段代码在VC6.0下,会报如下错误:
error C2664: '__thiscall std::vector<int,class std::allocator<int> >::std::vector<int,class std::allocator<int> >(unsigned int,const int &,const class std::allocator<int> &)' : cannot convert parameter 1 from 'class std::list<int,class std::allocator<int> >::iterator' to 'unsigned int' (指向上面红色语句)

在VS2010下,不会报错。

问题:
1、这段代码符合容器的初始化规则,为什么VC6.0下回报错?是否是VC6.0的编译器不支持容器的这种初始化方式?
2、如果要在VC6.0下执行这段代码,应该怎么做?
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
demystify
VC/MFC 16,550 成员 421,606 内容