//实现复数的前置++和后置++(利用成员函数运算符重载)
#include <iostream>
using namespace std;
class Com
{
public:
int a, b;
Com(int i = 0,int j = 0) :a(i), b(j) {};
Com& operator++();//前置++
Com operator++(int);//后置++
void show();
};
Com& Com::operator++()
{
a++;
b++;
return *this;
}
Com Com::operator++(int)
{
Com old;
old.a = a;
old.b = b;
a++;
b++;
return old;
}
void Com::show()
{
cout << a << "+" << b << "i" << endl;
}
int main()
{
Com a(4, 5);
a.show();
Com b = ++a;
a.show();
b.show();
Com c = a++;
a.show();
return 0;
}