C++:编译器看不到重载运算符

C++: Compiler doesn't see overloaded operator

本文关键字:重载 运算符 看不到 编译器 C++      更新时间:2023-10-16

我一直在尝试实现链表迭代器类。当我使用重载"!"

for (itr = (test0.begin()); itr != (test0.end()); ++itr)
{
    cout << *itr;
}

错误如下:

error: no match for ‘operator!=’ in ‘itr != SinglyLinkedList<Object>::end() [with Object = int]()’

我不明白为什么它不能找到匹配,因为test0.end()和itr都是迭代器。

下面是重载操作符的代码:

bool operator!= (iterator &rhs)
{
    return (this->current != rhs.current);
}

我怀疑这是因为常量正确性:

bool operator!= (iterator const &rhs) const
{
    return (this->current != rhs.current);
}