我在使用基本代碼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