2
votes

I am new to the usage of iterators. I have used the below code, where I parse through all the elements in the list using iterator, to determine whether the element exists in the list or not.

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;
   }
}

The code works fine, but I am getting the below Lint warning:

Info 1702: operator 'operator!=' is both an ordinary function 'operator!=(const pair<<1>,<2>> &, const pair<<1>,<2>> &)' and a member function 'list::const_iterator::operator!=(const const_iterator &) const'

What does the above warning mean? Is it conflict between operator overloading implementation of != operator in list and iterator?

1
Nothing to do with the question, but use std::find instead of the for loop. - Jesse Good
Yeah std::find is a better one. Thanks for the suggestion - inquisitive

1 Answers

3
votes

It means precisely what it says. The list iterator is a pair and pair has an operator!= function, but the list iterator class also has its own operator!= function. Since both operators do precisely the same thing (because any two pairs that match on the first element match on the second as well), you can safely ignore the warning.