极客班GeekBand - C++面向对象高级开发 - 2
讲师 - 侯捷
复习Complex类的实现过程
Complex.h
#ifndef __COMPLEX__
#define __COMPLEX__
#include <iostream>
using namespace std;
class complex {
private:
double re, im;
public:
complex(double r = 0, double i = 0) :re(r), im(i) {
}
complex& operator += (const complex&);
double real() const {
return re;
}
double imag() const {
return im;
}
friend complex& __doapl(complex*, const complex&);
};
inline complex& complex::operator+= (const complex& r) {
return __doapl(this, r);
}
inline complex& __doapl(complex* ths, const complex& r) {
ths->re += r.re;
ths->im += r.im;
return *ths;
}
inline complex operator +(const complex& x, const complex& y) {
return complex(x.real() + y.real(), x.imag() + y.imag());
}
inline complex operator +(const