错误:'operator=='不匹配
error: no match for '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
是否有比较运算符?如果有,它是否将其两个论点都视为const
?特别是,如果您比较运算符是成员,则很容易忘记将其设为const
成员:
bool Int::operator== (Int const& other) const {
...
}
根据错误,element
不是int
而是Link<Int>
。您需要将Int
从Link
中取出,并将其转换为具有operator==
的东西(请注意,Int
不是int
)。
相关文章:
- 与'operator='不匹配(操作数类型'String'且"void")
- Valarray 切片数组与 'operator*' 不匹配
- 错误:'operator>'不匹配(操作数类型为 'Student' 和 'Student'
- 与'operator<<'不匹配(操作数类型'std::ostream {aka std::basic_ostream<char>}'
- 与"operator<<"不匹配(操作数类型'std::ostream'
- C++ 重载:[错误] 与'operator='不匹配(操作数类型为 'String' 和"字符串")
- 使用标准::时间::high_resolution_clock时"operator ="不匹配
- 错误:与'operator='不匹配(操作数类型为 'PlDrustvo' 和"PlDrustvo")|
- 错误:与'operator='不匹配(操作数类型为"std::map<int、double>::iterator
- 错误:尝试减去字符串时'operator-'不匹配
- 调用模板方法会导致'operator<'不匹配
- \main.cpp|103|error: 与"operator<<"不匹配(操作数类型为"std::ostream {aka std::basic_ostream<char&g
- 使用 #omp 时'operator -'不匹配
- 尝试使用 fstream 将字符写入文件:'operator<<'不匹配
- C++ 将文件读取到数组错误:'operator>>'不匹配
- 有没有办法修复此错误:与'operator[]'不匹配(操作数类型为 'empl' 和"int")
- 错误与'operator='不匹配(操作数类型为 'Person' 和"Person*")
- 我得到"将值分配给结构数组 iin 时与'operator='不匹配C++
- 在地图中搜索值时'operator='不匹配
- 错误:'operator<<'和"运算符>>"不匹配。请帮忙?