- 数据要封装(尽量private)
- 参数和返回值尽量用reference(返回local variable除外)
- 能用const一定要用const
- 构造函数尽量用initializer_list进行参数初始化
临时对象是指在函数作用域或块作用域内定义的变量。
临时对象在需要返回一个新对象时,可以有效减少代码的冗余,比如:
# complex.h, derived from ppt
...
省略代码
...
inline complex
operator + (double x, const complex&y)
{
return complex(x + real(y), imag(y));
}