class MyCmplx {
public:
double re;
double im;
MyCmplx(double r, double i) { re = r; im = i; }
MyCmplx() { re = im = 0; }
};
static MyCmplx operator+ (MyCmplx& lhs, MyCmplx& rhs) {
MyCmplx ret(0,0);//re, im
ret.re = lhs.re + rhs.re;
ret.im = lhs.im + rhs.im;
return ret;
}
ostream& operator << (ostream& strm, MyCmplx& rhs) {
return strm << "(" << rhs.re << ", " << rhs.im << "*i)";
}
int main()
{// (4 + 5i) + (7 + 3i)
MyCmplx c1(4, 5);
MyCmplx c2 (7, 3);
cout << c1 << endl << c2 << endl;
MyCmplx c3;
c3 = c1 + c2;
cout << c1 << " + " << c2 << " = " << c3 << endl;
MyCmplx c4;
c2.re = 0;
c2.im = 0;
}