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.
the back() return the element not the iterator. so use code
return *itTypes != pList->back()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With