我有一个自定义迭代器模板类,它包装了一个std::list迭代器.在我的hasNext()方法中,我想检查迭代器是否引用列表中的最后一项.但是这段代码:
template< class Type >
...
virtual bool hasNext( void )
{
return itTypes != pList->back();
}
...
typename std::list< Type > * pList;
typename std::list< Type >::iterator itTypes;
Run Code Online (Sandbox Code Playgroud)
产生错误:
error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::_List_iterator<_Mylist>'
如果我比较itTypes来list::begin()或list::end()我没有得到任何问题.我在STL迭代器中看到的文档说std :: list使用的双向迭代器支持相等和不等式比较运算符.有什么理由我无法与之比较list::back()吗?