#include<iostream>
using namespace std;
class complex
{
public:
complex(int a = 0, int b = 0) :real(a), imag(b) {}
complex operator++();//前置
complex operator++(int);//后置
friend ostream&operator << (ostream&, complex&);
friend istream& operator >>(istream&, complex&);
private:
int real, imag;
};
complex complex::operator++(int) {
return complex(real++, imag++);
}
complex complex::operator++() {
/*real++;
imag++;
return *this;*/
return complex(++real, ++imag);
}
ostream& operator<<(ostream& output, complex& c){
output << c.real << "." << c.imag << endl;
return output;
}
istream& operator>>(istream& input, complex& c) {
input >> c.real >> c.imag;
return input;
}
int main() {
complex c1,c2;
cin >> c1;
cout << c1;
c2 = ++c1;
cout<<c2<<endl;
cout << c1;
c1++;
cout << c1;
return 0;
}
输入
1
2
输出:
1.2
2.3
2.3
3.4