错误:候选函数不可行:'this'参数具有类型 'const' 但方法未标记为 const

Error: candidate function not viable: 'this' argument has type 'const' but method is not marked const

本文关键字:const 记为 方法 类型 参数 不可行 候选函数 this 错误      更新时间:2023-10-16

我已经遇到了一些试图编译项目的问题。它一直给我留言:"候选函数不可行:'此'参数具有类型为'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;
    }
}

如果有人有任何想法或知道我使用const的问题,我将非常感激。

更改以下内容:

bool operator==(const node& x) {

bool operator==(const node& x) const {

为了标记您的其他功能const。