Jet*_*ope 0 c++ constants function operator-keyword
我在尝试编译项目时遇到了一些问题。它不断给我消息:“候选函数不可行:'this'参数的类型为'const',但方法未标记为const”。以下是出现此错误的函数。
bool operator<(const node& x) const{
if(name < x.name){
return true;
} else{
return false;
}
}
bool operator==(const node& x){
if(name == x.name){
return true;
} else{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人有任何想法或知道我在使用 const 时出了什么问题,我将非常感激。
改变这个:
bool operator==(const node& x) {
Run Code Online (Sandbox Code Playgroud)
对此:
bool operator==(const node& x) const {
Run Code Online (Sandbox Code Playgroud)
为了也标记你的其他函数 const 。
| 归档时间: |
|
| 查看次数: |
6794 次 |
| 最近记录: |