【问题标题】:why i have this error overloading an operator?为什么我有这个错误重载运算符?
【发布时间】:2019-03-29 08:37:57
【问题描述】:

我想定义一个运算符来对对象向量“esame”进行排序,但我有这个错误:

/* esame.cpp:46:6: 错误:'bool 的原型 esame::operator

     bool operator<(const esame &) const

    //this is the declaration on the header file:

    bool operator<(const esame &) const;





    //this is implementation on the cpp file:

    bool esame::operator<(esame &exam) const
    {
        if (this->getNome() < exam.getNome()){
            return true;
        } else{
            return false;
        }  
    }

【问题讨论】:

  • 与错误无关,但this-&gt;getNome() &lt; exam.getNome()的结果已经是bool。你不需要if

标签: c++


【解决方案1】:

签名不同。在实现中将const 添加到esame &amp;exam

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 2011-08-19
    • 2015-11-13
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多