Reputation: 1320
I have stuck on my try to implement linked list iterator class. Compiler is complaining when I use overloaded "!=" operator here:
for (itr = (test0.begin()); itr != (test0.end()); ++itr)
{
cout << *itr;
}
Here is the error:
error: no match for ‘operator!=’ in ‘itr != SinglyLinkedList<Object>::end() [with Object = int]()’
I don't understand why it can't find the match, because both test0.end() and itr are iterators.
Here is the code of overloaded operator:
bool operator!= (iterator &rhs)
{
return (this->current != rhs.current);
}
Thanks in advance.
Upvotes: 1
Views: 942
Reputation: 18228
I suspect that this is because of const-correctness:
bool operator!= (iterator const &rhs) const
{
return (this->current != rhs.current);
}
Upvotes: 5