我已经实现了一个双向链表,并创建了一个可扩展的迭代器std::iterator
。我现在正在尝试创建一个const
版本。
我试过了:
typename typedef list_iterator<T_> iterator;
typename typedef list_iterator<T_> const const_iterator;
如果我这样做,我会收到此错误:
error C2678: binary '--' : no operator found which takes a left-hand operand of type 'const list_iterator<T_>' (or there is no acceptable conversion)
这是我的operator--
:
list_iterator& operator -- ()
{
_current = _current->_previous;
return *this;
}
list_iterator operator--(int) // postfix
{
list_iterator hold = *this;
--*this;
return list_iterator( hold );
}
如果我把
list_iterator operator--() const
...我无法修改_current
我如何使我的迭代器现在像 a 一样工作,const_iterator
以便从我的链表中我可以调用获取 and 的 const 版本begin()
,end()
以及cbegin()
and cend()
?