C++ 错误:与‘;不匹配;运算符==’;(操作数类型为‘;常量类’;和‘;常量类’;)如果(object1==object2)

C++ 错误:与‘;不匹配;运算符==’;(操作数类型为‘;常量类’;和‘;常量类’;)如果(object1==object2),c++,C++,我的代码有一些错误,我不知道如何解决。 错误是: error: no match for ‘operator==’ (operand types are ‘const Secuencia’ and const Secuencia’) if (sec1 == sec2) note: candidate: ‘bool Secuencia::operator==(const Secuencia&)’ bool operator == (const Secuencia & otro); note:

我的代码有一些错误,我不知道如何解决。 错误是:

error: no match for ‘operator==’ (operand types are ‘const Secuencia’ and const Secuencia’) if (sec1 == sec2) note: candidate: ‘bool Secuencia::operator==(const Secuencia&)’ bool operator == (const Secuencia & otro); note: passing ‘const Secuencia*’ as ‘this’ argument discards qualifiers 在我的.cpp中:

bool Secuencia :: operator == (const Secuencia & other){

    bool same = (used == other.used && capacity == other.capacity ? true:false);

    if(same == true){

        for(int i = 0; i < used && same == true; i++){
            if(info[i] != otro.info[i])
                same = false;
        }

    }

    return (same);
}
bool Secuencia::operator==(const Secuencia和other){
bool same=(used==other.used&&capacity==other.capacity?true:false);
如果(相同==true){
for(int i=0;i
如果将
运算符==
定义为成员函数,则它应该是
常量

       bool operator == (const Secuencia & other) const;

您的运算符应为常量方法:bool运算符==(const Secuencia&other)const;非常感谢。我没有意识到
       bool operator == (const Secuencia & other) const;