#include <iostream>
using namespace std;
class Complex
{
private:
int age;
int num;
public:
//无参构造
Complex()
{}
//有参构造
Complex(int age,int num)
{
this->age = age;
this->num = num;
}
void show()
{
cout << "age" << age << "num" << num <<endl;
}
Complex operator+(Complex &a)
{
Complex temp;
temp.age = this->age+a.age;
temp.num = this->num+a.num;
return temp;
}
Complex operator-(Complex &a)
{
Complex temp;
temp.age = this->age-a.age;
temp.num = this->num-a.num;
return temp;
}
Complex operator*(Complex &a)
{
Complex temp;
temp.age = this->age*a.age;
temp.num = this->num*a.num;
return temp;
}
Complex operator/(Complex &a)
{
Complex temp;
temp.age = this->age/a.age;
temp.num = this->num/a.num;
return temp;
}
Complex operator%(Complex &a)
{
Complex temp;
temp.age = this->age%a.age;
temp.num = this->num%a.num;
return temp;
}
//先自增
Complex &operator++()
{
Complex temp;
temp.age=++age;
temp.num=++num;
return temp;
}
//后自增
Complex &operator++(int)
{
Complex temp;
temp.age = this->age++;
temp.num = this->num++;
return *this;
}
//逻辑非运算
Complex operator!()
{
Complex temp;
temp.age=!age;
temp.num=!num;
return temp;
}
//乘等于
Complex operator*=(Complex &a)
{
this->age*=a.age;
this->num*=a.num;
return *this;
}
//除等于
Complex operator/=(Complex &a)
{
this->age/=a.age;
this->num/=a.num;
return *this;
}
};
int main()
{
Complex a;
Complex a1(2,4);
Complex a2(3,6);
Complex a3 = a1+a2;
a3.show();
a2*=a1;
a3.show();
return 0;
}