【发布时间】:2012-02-05 20:24:42
【问题描述】:
我不熟悉迭代器的使用。我使用了下面的代码,其中我使用迭代器解析列表中的所有元素,以确定该元素是否存在于列表中。
list<int> pendingRsp;
list<int>::iterator it1;
for(int i = 1; i <= 5; i++)
pendingRsp.push_back(i *10);
for(it1 = pendingRsp.begin(); it1 != pendingRsp.end(); it1++)
{
if((*it1) == 50)
{
found = true;
break;
}
}
代码运行良好,但我收到以下 Lint 警告:
Info 1702: operator 'operator!=' 是一个普通函数 'operator!=(const pair,> &, const pair,> &)' 和成员函数 'list::const_iterator::operator!=(const const_iterator &) const'
上面的警告是什么意思?列表中!=运算符的运算符重载实现与迭代器之间是否存在冲突?
【问题讨论】:
-
与问题无关,但使用
std::find而不是for循环。 -
是的 std::find 更好。感谢您的建议