简体   繁体   English

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

[英]C++: Compiler doesn't see overloaded operator

I have stuck on my try to implement linked list iterator class. 我一直在尝试实现链接列表迭代器类。 Compiler is complaining when I use overloaded "!=" operator here: 当我在此处使用重载的“!=”运算符时,编译器会抱怨:

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

Here is the error: 这是错误:

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

I don't understand why it can't find the match, because both test0.end() and itr are iterators. 我不明白为什么找不到匹配项,因为test0.end()和itr都是迭代器。

Here is the code of overloaded operator: 这是重载运算符的代码:

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

Thanks in advance. 提前致谢。

I suspect that this is because of const-correctness: 我怀疑这是因为const-正确性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM