inquisitive
inquisitive

Reputation: 1680

Iterator usage - Lint warning

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?

Upvotes: 2

Views: 663

Answers (1)

David Schwartz
David Schwartz

Reputation: 182829

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.

Upvotes: 3

Related Questions