高质量C++C 编程指南.pdf
文件大小: 637k
源码售价: 10 个金币 积分规则     积分充值
资源说明:前 言 ....................................................................................................................................6 第 1 章 文件结构............................................................................................................... 11 1.1 版权和版本的声明 ................................................................................................... 11 1.2 头文件的结构...........................................................................................................12 1.3 定义文件的结构.......................................................................................................13 1.4 头文件的作用...........................................................................................................13 1.5 目录结构 ..................................................................................................................14 第 2 章 程序的版式 ...........................................................................................................15 2.1 空行 ..........................................................................................................................15 2.2 代码行 ......................................................................................................................16 2.3 代码行内的空格.......................................................................................................17 2.4 对齐 ..........................................................................................................................18 2.5 长行拆分 ..................................................................................................................19 2.6 修饰符的位置...........................................................................................................19 2.7 注释 ..........................................................................................................................20 2.8 类的版式 ..................................................................................................................21 第 3 章 命名规则...............................................................................................................22 3.1 共性规则 ..................................................................................................................22 3.2 简单的 WINDOWS 应用程序命名规则 ......................................................................23 3.3 简单的 UNIX 应用程序命名规则..............................................................................25 第 4 章 表达式和基本语句................................................................................................26 4.1 运算符的优先级.......................................................................................................26 4.2 复合表达式...............................................................................................................27 4.3 IF 语句 ......................................................................................................................27 4.4 循环语句的效率.......................................................................................................29 4.5 FOR 语句的循环控制变量.........................................................................................30 4.6 SWITCH 语句 ..............................................................................................................30 4.7 GOTO 语句..................................................................................................................31 第 5 章 常量.......................................................................................................................33 5.1 为什么需要常量.......................................................................................................33 5.2 CONST 与 #DEFINE 的比较 ........................................................................................33 5.3 常量定义规则...........................................................................................................33 5.4 类中的常量...............................................................................................................34 第 6 章 函数设计...............................................................................................................36 高质量 C++/C 编程指南,v 1.0 2001 Page 4 of 101 6.1 参数的规则...............................................................................................................36 6.2 返回值的规则...........................................................................................................37 6.3 函数内部实现的规则 ...............................................................................................39 6.4 其它建议 ..................................................................................................................40 6.5 使用断言 ..................................................................................................................41 6.6 引用与指针的比较 ...................................................................................................42 第 7 章 内存管理...............................................................................................................44 7.1 内存分配方式 ...........................................................................................................44 7.2 常见的内存错误及其对策 ........................................................................................44 7.3 指针与数组的对比....................................................................................................45 7.4 指针参数是如何传递内存的?.................................................................................47 7.5 FREE 和 DELETE 把指针怎么啦? ..............................................................................50 7.6 动态内存会被自动释放吗?....................................................................................50 7.7 杜绝“野指针”.......................................................................................................51 7.8 有了 MALLOC/FREE 为什么还要 NEW/DELETE ?......................................................52 7.9 内存耗尽怎么办? ...................................................................................................53 7.10 MALLOC/FREE 的使用要点 ......................................................................................54 7.11 NEW/DELETE 的使用要点 ........................................................................................55 7.12 一些心得体会.........................................................................................................56 第 8 章 C++函数的高级特性 ............................................................................................57 8.1 函数重载的概念.......................................................................................................57 8.2 成员函数的重载、覆盖与隐藏 ................................................................................60 8.3 参数的缺省值...........................................................................................................63 8.4 运算符重载...............................................................................................................64 8.5 函数内联 ..................................................................................................................65 8.6 一些心得体会...........................................................................................................68 第 9 章 类的构造函数、析构函数与赋值函数 .................................................................69 9.1 构造函数与析构函数的起源....................................................................................69 9.2 构造函数的初始化表 ...............................................................................................70 9.3 构造和析构的次序 ...................................................................................................72 9.4 示例:类 STRING 的构造函数与析构函数 ...............................................................72 9.5 不要轻视拷贝构造函数与赋值函数.........................................................................73 9.6 示例:类 STRING 的拷贝构造函数与赋值函数........................................................73 9.7 偷懒的办法处理拷贝构造函数与赋值函数 .............................................................75 9.8 如何在派生类中实现类的基本函数.........................................................................75 9.9 一些心得体会...........................................................................................................77 第 10 章 类的继承与组合..................................................................................................78 高质量 C++/C 编程指南,v 1.0 2001 Page 5 of 101 10.1 继承 ........................................................................................................................78 10.2 组合 ........................................................................................................................80 第 11 章 其它编程经验......................................................................................................82 11.1 使用 CONST 提高函数的健壮性 ..............................................................................82 11.2 提高程序的效率 .....................................................................................................84 11.3 一些有益的建议 .....................................................................................................85 参考文献 ............................................................................................................................87 附录 A :C++/C 代码审查表............................................................................................88 附录 B :C++/C 试题 .......................................................................................................93 附录 C :C++/C 试题的答案与评分标准.........................................................................97
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。