• 如下程序定义了“单词”类word,类中重载了<运算符,用于比较“单词”的大小,返回相应的逻辑值。程序的输出结果为:After Sorting:Happy Welcome,请将程序补充完整。
    include<iostream>
    include<string>
    using namespace std;
    class Word{
    public:
    Word(strings):str(s){ }
    string getStr( ){return str;}
    ______const{return(str<w.str);}
    friend ostream& operator<<(ostream& output,const Word &w){output<<w.str;return output;}
    private:
    string str;
    };
    int main( ){
    Word wl("Happy"),w2("Welcome");
    cout<<"After sorting:";
    if(wl<w2)cout<<w1<<"<<w2;
    else cout<<w2<<''<<w1:
    return 0;
    }

    正确答案:bool operator(Word w)bool operator(Word w) 解析:重载关系运算符“”为成员函数,得到逻辑类型结果,且只要一个参数。
  • 2021年06月30日 21时14分来自  问答库 >> 计算机类
  • 评论 0
  • 手机玩微博

    手机版 手机端
    Powered by 日新微博 © 2018 - 2020 日新网