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