I have a custom iterator template class that wraps up a std::list iterator. In my hasNext() method I want to check to see if the iterator refers to the last item in the list. However this code:
template< class Type >
...
virtual bool hasNext( void )
{
return itTypes != pList->back();
}
...
typename std::list< Type > * pList;
typename std::list< Type >::iterator itTypes;
Produces the error:
error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::_List_iterator<_Mylist>'
If I compare itTypes to list::begin() or list::end() I get no problem. The documentation I’ve looked at for STL iterators says that the bidirectional iterators used by std::list support the equality and inequality comparison operators. Is there a reason I can’t compare to list::back() then?
You want
end().back()gets the value of the last element, which is not an iterator into the list at all.