我在使用基本代码this data structures book实现链接列表的搜索功能时遇到了一些麻烦。这是我得到的错误:错误:'operator =='不匹配
llist.h: In member function 'void LList<E>::search(const E&, bool&) [with E = Int]':
Llistmain.cpp:31:1: instantiated from here
llist.h:119:3: error: no match for 'operator==' in '((LList<Int>*)this)->LList<Int>::curr->Link<Int>::element == value'
这里是我的搜索成员函数的实现:
void search(const E& value, bool& found) {
if (curr->element == value)
found = true;
else if (curr != NULL) {
curr = curr->next;
search(value, found);
}
else found = false;
}
为什么我会得到一个错误有关== operator
? curr->element
和value
都是Int类型。我应该以不同的方式检查平等吗?
这解决了这个问题。我为Int提出了一个重载的比较运算符,并解决了问题。谢谢。 – beastmaster