#include
using namespace std;
class Stu
{
friend const Stu operator+(const Stu &L, const Stu &R);
friend const Stu operator-(const Stu &L, const Stu &R);
friend const Stu operator*(const Stu &L, const Stu &R);
friend const Stu operator/(const Stu &L, const Stu &R);
friend bool operator>(const Stu &L, const Stu &R);
friend bool operator>=(const Stu &L, const Stu &R);
friend bool operator<(const Stu &L, const Stu &R);
friend bool operator<=(const Stu &L, const Stu &R);
friend bool operator==(const Stu &L, const Stu &R);
friend bool operator!=(const Stu &L, const Stu &R);
int a;
int b;
public:
Stu(int a = 0, int b = 0):a(a), b(b){}
void show(){
cout << "a = " << a << endl;
cout << "b = " << b << endl;
}
// const Stu operator+(const Stu &R) const{
// Stu temp;
// temp.a = a + R.a;
// temp.b = b + R.b;
// return temp;
// }
// Stu(const Stu &other):a(other.a), b(other.b){
// cout << "拷贝构造函数" << endl;
// }
Stu &operator=(const Stu &other){
a = other.a;
b = other.b;
cout << "拷贝赋值函数" << endl;
return *this;
}
};
const Stu operator+(const Stu &L, const Stu &R){
Stu temp;
temp.a = L.a + R.a;
temp.b = L.b + R.b;
return temp;
}
const Stu operator-(const Stu &L, const Stu &R){
Stu temp;
temp.a = L.a - R.a;
temp.b = L.b - R.b;
return temp;
}
const Stu operator*(const Stu &L, const Stu &R){
Stu temp;
temp.a = L.a * R.a;
temp.b = L.b * R.b;
return temp;
}
const Stu operator/(const Stu &L, const Stu &R){
Stu temp;
temp.a = L.a / R.a;
temp.b = L.b / R.b;
return temp;
}
bool operator>(const Stu &L, const Stu &R){
return (L.a > R.a) && (L.b > R.b);
}
bool operator>=(const Stu &L, const Stu &R){
return (L.a >= R.a) && (L.b >= R.b);
}
bool operator<(const Stu &L, const Stu &R){
return (L.a < R.a) && (L.b < R.b);
}
bool operator<=(const Stu &L, const Stu &R){
return (L.a <= R.a) && (L.b <= R.b);
}
bool operator==(const Stu &L, const Stu &R){
return (L.a == R.a) && (L.b == R.b);
}
bool operator!=(const Stu &L, const Stu &R){
return (L.a != R.a) && (L.b != R.b);
}
int main()
{
Stu p1(1,1);
Stu p2(2,2);
Stu p3 = p1 + p1;
p3.show();
cout << "---------------" << endl;
// Stu p4 = p1 - p2;
// p4.show();
// Stu p5 = p1 * p2;
// p5.show();
// Stu p6 = p1 / p2;
// p6.show();
if(p3 > p1)
cout << "p3 > p1" << endl;
if(p2 >= (p1+p1))
cout << "p2 >= p1+p1" << endl;
if(p1 < p2)
cout << "p1 < p2" << endl;
if(p1 <= p2)
cout << "p1 <= p2" << endl;
if(p3 == p2)
cout << "p3 == p2" << endl;
if(p1 != p2)
cout << "p1 != p2" << endl;
return 0;
}