高级用法:initialization list
class complex
{
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; }
private:
double re, im;
friend complex& __doapl (complex*, const complex&);
};
上面的代码:
complex (double r = 0, double i = 0)
: re (r), im (i) // 初始化高级用法
{ }
只有构造函数才会有的写法,类似于:
complex (double r = 0, double i = 0)
{ re = r; im = i; }