10.2总结

cpp 复制代码
#include <iostream>

using namespace std;

class MyString
{
private:
    string pos1;
    string pos2;
public:
    MyString()
    {}
    MyString(string pos1,string pos2):pos1(pos1),pos2(pos2)
    {
        cout << "调用了有参构造" << endl;
    }
    MyString(const MyString &other):pos1(other.pos1),pos2(other.pos2)
    {
        cout << "调用了拷贝构造函数" << endl;
    }
    const MyString operator+(const MyString &R)const
    {
        MyString t;
        t.pos1 = pos1+R.pos1;
        t.pos2 = pos2+R.pos2;
        return  t;
    }

    const MyString operator>(const MyString &R)const
    {
        MyString t;
        t.pos1 = (pos1>R.pos1)?"true":"false";
        t.pos2 = (pos2>R.pos2)?"true":"false";
        return  t;
    }
    const MyString operator<(const MyString &R)const
    {
        MyString t;
        t.pos1 = (pos1<R.pos1)?"true":"false";
        t.pos2 = (pos2<R.pos2)?"true":"false";
        return  t;
    }
    const MyString operator==(const MyString &R)const
    {
        MyString t;
        t.pos1 = (pos1==R.pos1)?"true":"false";
        t.pos2 = (pos2==R.pos2)?"true":"false";
        return  t;
    }
    void input()
    {
        cout << "请输入pos1: ";
        cin >> pos1;
        cout << "请输入pos2: ";
        cin >> pos2;
    }


    void output() const
    {
        cout << "pos1: " << pos1 << ", pos2: " << pos2;
    }


    void show()
    {
        cout << "pos1的长度为" << pos1.size() << endl;
        cout << "pos2的长度为" << pos2.size() << endl;
        cout << "pos1= " << pos1 << " " << "pos2= " << pos2 << endl;

    }

};

int main()
{
    //    MyString s1("z","x");
    //    MyString s2("b","a");
    MyString s1;
    s1.input();
    // s1.output();
    MyString s2;
    s2.input();
    //s2.output();
    MyString s =s1+s2;
    MyString s3 =s1>s2;
    s.show();
    s3.show();
    return 0;
}

相关推荐
人道领域6 小时前
Java基础热门八股总结:八种基本数据类型 + 装箱拆箱 + 缓存机制,(90%的Java新手都搞不清的装箱拆箱问题)
java·开发语言·python
Deep-w6 小时前
【MATLAB】含光伏 - 储能的家庭/工业微电网能量管理仿真研究
开发语言·算法·matlab
菜鸟小九6 小时前
JUC补充(ThreadLocal、completableFuture)
java·开发语言
dyxal7 小时前
Louvain 算法:让网络自己“报团取暖”的发现者
开发语言·算法
计算机安禾7 小时前
【c++面向对象编程】第41篇:函数模板与类模板:泛型编程的基石
开发语言·c++·算法
熊猫_豆豆7 小时前
麦克斯韦方程组(电磁效应Python展示)
开发语言·python·电磁感应·麦克斯韦方程组
SilentSamsara7 小时前
属性查找顺序:实例 → 类 → 父类的完整 MRO
开发语言·python·算法·青少年编程
运维行者_7 小时前
云计算连接性与互操作性
服务器·开发语言·网络·web安全·网络基础设施
郝学胜-神的一滴7 小时前
Qt 高级开发 010: 从跨界面传值到自定义信号
开发语言·c++·qt·程序人生·用户界面
社交怪人7 小时前
【浮点数相除的余】信息学奥赛一本通C语言解法(题号1029)
c语言·开发语言