@让自己习惯C++ Accustoming Yourself to C++
1.视C++为一个语言联邦 View C++ as a federation of languages
2.尽量使用const,enum,inline 替换#define Perfer consts,enums,and inlines to #defines
3.尽可能使用const Use const whenever possible
4.确定对象被使用前已先被初始化 Make sure that objects are initialized before they're used
@构造/析构/赋值运算 Constructors,Destructors, and Assignment Operators
5.了解C++默默编写并调用哪些函数 Know what functions C++ silently writes and calls
6.若不想使用编译器自动生成的函数,就该明确拒绝 Explicitly disallow the use of compiler-generated functions you do not want
7.为多态基类声明virtual 析构函数 Declare destructors virtual in polymorphic base classes
8.别让异常逃离析构函数
9.绝不在构造和析构函数过程中调用virtual 函数
10.令operator =返回一个reference to *this
11.在operator = 中处理“自我赋值”
12.复制对象时勿忘其每一个成分
@资源管理
13.以对象管理资源
14.在资源管理类中小心copying行为
15.在资源管理类中提供对原始资源的访问
16.成对的使用new和delete时要采用相同形式
17.以独立语句将newed对象置入智能指针
@设计与声明
18.让接口容易被正确使用,不易被误用
19.设计class犹如设计type
20.宁以pass-by-reference-to-const替换pass-by-value
21.必须返回对象时,别妄想返回其reference
22.将成员变量声明为private
23.宁以non-member,non-friend替换member 函数
24.若所有参数皆需类型转换,请为此采用non-member函数
25.考虑写出一个不抛出异常的swap函数
@继承与面向对象的设计
34.区分接口继承和实现继承 接口继承与实现继承不同,在public继承之下,derived classes 总是继承base class的接口
pure virtual 函数只具体指定接口继承
简朴的(非纯)impure virtual 函数具体指定接口继承及缺省实现继承
non-virtual 函数具体制定接口继承以及强制性实现继承