第 1 章 基础............................................................................................................................1
1.1 引言 ...............................................................................................................................1
1.2 程序 ...............................................................................................................................2
1.2.1 Hello, World!................................................................................................................. 2
1.3 函数 ...............................................................................................................................4
1.4 类型、变量与运算........................................................................................................6
1.4.1 算术运算 ....................................................................................................................... 7
1.4.2 初始化........................................................................................................................... 9
1.5 作用域和生命周期...................................................................................................... 10
1.6 常量 ............................................................................................................................. 11
1.7 指针、数组和引用...................................................................................................... 13
1.7.1 空指针..........................................................................................................................15
1.8 检验 ............................................................................................................................. 16
1.9 映射到硬件 ................................................................................................................. 19
1.9.1 赋值..............................................................................................................................19
1.9.2 初始化..........................................................................................................................20
1.10 建议 ........................................................................................................................... 21
第 2 章 用户自定义类型........................................................................................................23
2.1 引言 ............................................................................................................................. 23
2.2 结构 ............................................................................................................................. 24
2.3 类 ................................................................................................................................. 25
2.4 枚举 ............................................................................................................................. 27
2.5 联合 ............................................................................................................................. 29
2.6 建议 ............................................................................................................................. 31
第 3 章 模块化 ......................................................................................................................32
3.1 引言 ............................................................................................................................. 32
3.2 分离编译 ..................................................................................................................... 33
3.2.1 头文件..........................................................................................................................34
3.2.2 模块..............................................................................................................................36
3.3 命名空间 ..................................................................................................................... 39
3.4 函数参数与返回值...................................................................................................... 41
3.4.1 参数传递 ......................................................................................................................42
3.4.2 返回值..........................................................................................................................43
3.4.3 返回类型推导 ..............................................................................................................45
3.4.4 返回类型后置 ..............................................................................................................45
3.4.5 结构化绑定 ..................................................................................................................46
3.5 建议 ............................................................................................................................. 47
第 4 章 错误处理...................................................................................................................48
4.1 引言 ............................................................................................................................. 48
4.2 异常 ............................................................................................................................. 49
4.3 约束条件 ..................................................................................................................... 50
4.4 错误处理的其他替代方式.......................................................................................... 52
4.5 断言 ............................................................................................................................. 54
4.5.1 assert() ..........................................................................................................................55
4.5.2 static_assert...................................................................................................................56
4.5.3 noexcept........................................................................................................................56
4.6 建议 ............................................................................................................................. 57
第 5 章 类..............................................................................................................................58
5.1 引言 ............................................................................................................................. 58
5.1.1 类的概述 ......................................................................................................................59
5.2 具体类型 ..................................................................................................................... 59
5.2.1 一种算术类型 ..............................................................................................................60
5.2.2 容器..............................................................................................................................62
5.2.3 容器的初始化 ..............................................................................................................64
5.3 抽象类型 ..................................................................................................................... 66
5.4 虚函数 ......................................................................................................................... 69
5.5 类层次结构 ................................................................................................................. 70
5.5.1 类层次结构的益处 .................................