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;
}

相关推荐
enfpZZ小狗几秒前
基于C++的反射机制探索
开发语言·c++·算法
曹牧几秒前
C#:WebReference
开发语言·c#
黎雁·泠崖4 分钟前
Java static入门:概述+静态变量特点与基础实战
java·开发语言
玉梅小洋4 分钟前
C盘爆满 修改VS Code缓存与插件目录指定方法
开发语言·windows·visualstudio
C#程序员一枚5 分钟前
C#AsNoTracking()详解
开发语言·c#
StandbyTime8 分钟前
C语言学习-菜鸟教程C经典100例-练习39
c语言
一条大祥脚9 分钟前
26.1.21 根号分治 相向双指针
java·开发语言·redis
涅小槃23 分钟前
Carla仿真学习笔记(版本0.9.16)
开发语言·python·ros·carla
wujialaoer25 分钟前
常用软件阿里源地址
开发语言·python
仰泳之鹅37 分钟前
【杂谈】C语言中的链接属性、声明周期以及static关键字
java·c语言·前端