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

相关推荐
leo_2323 分钟前
从开发语言角度来谈谈SMP(上)--SMP(软件制作平台)语言基础知识之十三
开发语言·开发工具·smp(软件制作平台)·应用系统
Larry_Yanan8 小时前
Qt多进程(三)QLocalSocket
开发语言·c++·qt·ui
醒过来摸鱼8 小时前
Java classloader
java·开发语言·python
superman超哥8 小时前
仓颉语言中元组的使用:深度剖析与工程实践
c语言·开发语言·c++·python·仓颉
小鸡吃米…8 小时前
Python - 继承
开发语言·python
JIngJaneIL9 小时前
基于java+ vue农产投入线上管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
祁思妙想9 小时前
Python中的FastAPI框架的设计特点和性能优势
开发语言·python·fastapi
唐装鼠9 小时前
rust自动调用Deref(deepseek)
开发语言·算法·rust
Lucas555555559 小时前
现代C++四十不惑:AI时代系统软件的基石与新征程
开发语言·c++·人工智能
源代码•宸9 小时前
goframe框架签到系统项目(BITFIELD 命令详解、Redis Key 设计、goframe 框架教程、安装MySQL)
开发语言·数据库·经验分享·redis·后端·mysql·golang