其余部分在有道云笔记里面
//Code is tested based on Visual Studio 2015.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Complex {
private:
double real, imag;
public:
Complex(double x, double y) {
real = x;
imag = y;
}
Complex() {}
double gr() { return real; }
double gi() { return imag; }
};
ostream & operator<<(ostream & o,Complex & c) {
o << c.gr() << "+" << c.gi() << "i";
return o;
}
int main() {
Complex c(2,4);
cout << c << endl << c << endl;
system("pause");
return 0;
}