Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1481963
  • 博文数量: 465
  • 博客积分: 8915
  • 博客等级: 中将
  • 技术积分: 6365
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-30 15:05
文章分类

全部博文(465)

文章存档

2017年(33)

2016年(2)

2015年(4)

2014年(29)

2013年(71)

2012年(148)

2011年(178)

分类: C/C++

2012-11-16 09:26:52

传世经典书丛

C++ Primer(第4版)(评注版)

(美)李普曼(Lippman,S.B.),(美)拉乔伊(Lajoie,J.),(美)莫(Moo,B.E.)著

陈硕 评注

ISBN 978-7-121-17441-4

20127月出版

定价:108.00

16

688

宣传语

这本重生的经典书籍教你快速且高效地编写现代C++程序

C++ Primer》是一本系统而权威的C++教材,它全面而深入地讲解了C++语言及其标准库。本书作者Stanley B. Lippman20世纪80年代早期即在C++之父Bjarne Stroustrup领导下开发C++编译器,另一作者Josée Lajoie曾多年担任C++标准委员会核心语言组主席,他们对这门编程语言的理解与把握非常人可比。本书对C++语法和语义的阐释兼具准确性与可读性,在坊间无出其右者。第4版更吸收了先进的C++教学经验,在内容组织上对初学者更加友好,详略得当且重点突出,使读者能更快上手编写有用的程序,也更适合自学。全球已有45万人通过该书的各个版本学习了C++编程。

对于国外技术图书,选择翻译版还是影印版,常常让人陷入两难的境地。本评注版力邀国内资深专家执笔,在英文原著基础上增加中文点评与注释,旨在融合二者之长,既保留经典的原创文字与味道,又以先行者的学研心得与实践感悟,对读者阅读与学习加以点拨、指明捷径。

经过评注的版本,更值得反复阅读与体会。希望这本书能够帮助您跨越C++的重重险阻,领略高处才有的壮美风光,做一个成功而快乐的C++程序员。

 

从《C++ Primer(第4版)》入手学习C++

为什么要学习C++

2009年本书作者Stanley Lippman先生来华参加上海祝成科技举办的C++技术大会,他表示人们现在还用C++的唯一理由是其性能。相比之下,Java/C#/Python等语言更加易学易用并且开发工具丰富,它们的开发效率都高于C++。但C++目前仍然是运行最快的语言 ,如果你的应用领域确实在乎这个性能,那么C++是不二之选。

这里略举几个例子 。对于手持设备而言,提高运行效率意味着完成相同的任务需要更少的电能,从而延长设备的操作时间,增强用户体验。对于嵌入式 设备而言,提高运行效率意味着:实现相同的功能可以选用较低档的处理器和较少的存储器,降低单个设备的成本;如果设备销量大到一定的规模,可以弥补C++开发的成本。对于分布式系统而言,提高10%的性能就意味着节约10%的机器和能源。如果系统大到一定的规模(数千台服务器),值得用程序员的时间去换取机器的时间和数量,可以降低总体成本。另外,对于某些延迟敏感的应用(如游戏 、金融交易),通常不能容忍垃圾收集(GC)带来的不确定延时,而C++可以自动并精确地控制对象销毁和内存释放时机 。我曾经不止一次见到,出于性能原因,用C++重写现有的JavaC#程序。

C++之父Bjarne StroustrupC++定位于偏重系统编程(system programming 的通用程序设计语言,开发信息基础架构(infrastructure)是C++的重要用途之一 Herb Sutter总结道 C++注重运行效率(efficiency)、灵活性(flexibility 和抽象能力(abstraction),并为此付出了生产力(productivity)方面的代价 。用本书作者的话来说,就是“C++ is about efficient programming with abstractions”C++的核心价值在于能写出运行效率不打折扣的抽象)。

要想发挥C++的性能优势,程序员需要对语言本身及各种操作的代价有深入的了解 ,特别要避免不必要的对象创建 。例如下面这个函数如果漏写了&,功能还是正确的,但性能将会大打折扣。编译器和单元测试都无法帮我们查出此类错误,程序员自己在编码时须得小心在意。

inlineintfind_longest(conststd::vector& words)

{

  // std::max_element(words.begin(), words.end(), LengthCompare());

}

在现代CPU体系结构下,C++ 的性能优势很大程度上得益于对内存布局(memory layout)的精确控制,从而优化内存访问的局部性 locality of reference)并充分利用内存阶层(memory hierarchy)提速 ,这一点优势在近期内不会被基于GC的语言赶上

C++的协作性不如CJavaPython,开源项目也比这几个语言少得多,因此在TIOBE语言流行榜中节节下滑。但是据我所知,很多企业内部使用C++来构建自己的分布式系统基础架构,并且有替换Java开源实现的趋势。

学习C++只需要读一本大部头

C++不是特性(features)最丰富的语言,却是最复杂的语言,诸多语言特性相互干扰,使其复杂度成倍增加。鉴于其学习难度和知识点之间的关联性,恐怕不能用粗粗看看语法,就撸起袖子开干,边查Google边学习这种方式来学习C++,那样很容易掉到陷阱里或养成坏的编程习惯。如果想成为专业C++开发者,全面而深入地了解这门复杂语言及其标准库,你需要一本系统而权威 的书,这样的书必定会是一本八九百页的大部头

兼具系统性和权威性的C++教材有两本,C++之父Bjarne Stroustrup的代表作《The C++ Programming Language》和Stanley Lippman的这本《C++ Primer》。侯捷先生评价道:泰山北斗已现,又何必案牍劳形于墨瀚书海之中!这两本书都从C++盘古开天以来,一路改版,斩将擎旗,追奔逐北,成就一生荣光

从实用的角度,这两本书读一本即可,因为它们覆盖的C++知识点相差无几。就我个人的阅读体验而言,Primer更易读一些,我10年前深入学习C++正是用的《C++ Primer(第3版)》。这次借评注的机会仔细阅读了《C++ Primer(第4版)》,感觉像在读一本完全不同的新书。第4版的内容组织及文字表达比第3版进步很多 ,第3版可谓事无巨细、面面俱到;第4版则重点突出、详略得当,甚至篇幅也缩短了,这多半归功于新加盟的作者Barbara Moo

C++ Primer(第4版)》讲什么?适合谁读?

这是一本C++语言的教程,不是编程教程。本书不讲八皇后问题、Huffman编码、汉诺塔、约瑟夫环、大整数运算等经典编程例题,本书的例子和习题往往都跟C++本身直接相关。本书的主要内容是精解C++语法(syntax)与语意(semantics),并介绍C++标准库的大部分内容(含STL)。这本书在全世界C++教学领域的突出和重要,已经无须我再赘言

本书适合C++语言的初学者,但不适合编程初学者。换言之,这本书可以是你的第一本C++书,但恐怕不能作为第一本编程书。如果你不知道什么是变量、赋值、分支、条件、循环、函数,你需要一本更加初级的书 ,本书第1章可用做自测题。

如果你已经学过一门编程语言,并且打算成为专业C++开发者,从《C++ Primer(第4版)》入手不会让你走弯路。值得特别说明的是,学习本书不需要事先具备C语言知识。相反,这本书教你编写真正的C++程序,而不是披着C++外衣的C程序。

C++ Primer(第4版)》的定位是语言教材,不是语言规格书,它并没有面面俱到地谈到C++的每一个角落,而是重点讲解C++程序员日常工作中真正有用的、必须掌握的语言设施和标准库 。本书的作者一点也不炫耀自己的知识和技巧,虽然他们有十足的资本 。这本书用语非常严谨(没有那些似是而非的比喻),用词平和,讲解细致,读起来并不枯燥。特别是如果你已经有一定的编程经验,在阅读时不妨思考如何用C++来更好地完成以往的编程任务。

尽管英文原版书篇幅近900页,但其内容还是十分紧凑的,很多地方读一个句子就值得写一小段代码去验证。为了节省篇幅,本书经常修改前文代码中的一两行,来说明新的知识点,值得把每一行代码敲到机器中去验证。习题当然也不能轻易放过。

C++ Primer(第4版)》体现了现代C++教学与编程理念:在现成的高质量类库上构建自己的程序,而不是什么都从头自己写。这本书在第3章中介绍了stringvector这两个常用的类,立刻就能写出很多有用的程序。但作者不是一次性把string的上百个成员函数一一列举,而是有选择地讲解了最常用的那几个函数。

C++ Primer(第4版)》的代码示例质量很高,不是那种随手写的玩具代码。第10.4.2节实现了带禁用词的单词计数;第10.6利用标准库容器简洁地实现了基于倒排索引思路的文本检索;第15.9节又用面向对象方法扩充了文本检索的功能,支持布尔查询。值得一提的是,这本书讲解继承和多态时举的例子符合Liskov替换原则,是正宗的面向对象。相反,某些教材以复用基类代码为目的,常以人、学生、老师、教授雇员、经理、销售、合同工为例,这是误用了面向对象的复用

C++ Primer(第4版)》出版于2005年,遵循2003年的C++语言标准 C++新标准已于2011年定案(称为C++11),本书不涉及TR1 C++11,这并不意味着这本书过时了 。相反,这本书里沉淀的都是当前广泛使用的C++编程实践,学习它可谓正当时。评注版也不会越俎代庖地介绍这些新内容,但是会指出哪些语言设施已在新标准中废弃,避免读者浪费精力。

C++ Primer(第4版)》是平台中立的,并不针对特定的编译器或操作系统。目前最主流的C++编译器有两个,GNUG++和微软的Visual C++。实际上,这两个编译器阵营基本上模塑C++语言的行为。理论上讲,C++语言的行为是由C++标准规定的。但是 C++不像其他很多语言有官方参考实现,因此C++的行为实际上是由语言标准、几大主流编译器、现有不计其数的C++产品代码共同确定的,三者相互制约。C++编译器不光要尽可能符合标准,同时也要遵循目标平台的成文或不成文规范和约定,例如高效地利用硬件资源、兼容操作系统提供的C语言接口等。在C++标准没有明文规定的地方,C++编译器也不能随心所欲地自由发挥。学习C++的要点之一是明白哪些行为是由标准保证的,哪些是由实现(软硬件平台和编译器)保证的 ,哪些是编译器自由实现、没有保证的;换言之,明白哪些程序行为是可依赖的。从学习的角度,我建议如果有条件,不妨两个编译器都用 ,相互比照,避免把编译器和平台特定的行为误解为C++语言规定的行为。尽管不是每个人都需要写跨平台的代码,但也大可不必自我限定在编译器的某个特定版本,毕竟编译器是会升级的。

本着练从难处练,用从易处用的精神,我建议在命令行下编译运行本书的示例代码,并尽量少用调试器。另外,值得了解C++的编译链接模型 ,这样才能不被实际开发中遇到的编译错误或链接错误绊住手脚。(C++不像现代语言那样有完善的模块(module)和包(package)设施,它从C语言继承了头文件、源文件、库文件等古老的模块化机制,这套机制相对较为脆弱,需要花一定时间学习规范的做法,避免误用。)

就学习C++语言本身而言,我认为有几个练习非常值得一做。这不是重复发明轮子,而是必要的编程练习,帮助你熟悉、掌握这门语言。一是写一个复数类或者大整数类 ,实现基本的运算,熟悉封装与数据抽象。二是写一个字符串类,熟悉内存管理与拷贝控制。三是写一个简化的vector类模板,熟悉基本的模板编程,你的这个vector应该能放入intstring等元素类型。四是写一个表达式计算器,实现一个节点类的继承体系(右图),体会面向对象编程。前三个练习是写独立的值语义的类,第四个练习是对象语义,同时要考虑类与类之间的关系。

表达式计算器能把四则运算式3+24解析为左图的表达式树 ,对根节点调用calculate()虚函数就能算出表达式的值。做完之后还可以再扩充功能,比如支持三角函数和变量。

 

在写完面向对象版的表达式树之后,还可以略微尝试泛型编程。比如把类的继承体系简化为下图,然后用BinaryNode>BinaryNode>来具现化BinaryNode类模板,通过控制模板参数的类型来实现不同的运算。

 

 

在表达式树这个例子中,节点对象是动态创建的,值得思考:如何才能安全地、不重不漏地释放内存。本书第15.8节的Handle可供参考。(C++的面向对象基础设施相对于现代的语言而言显得很简陋,现在C++也不再以支持面向对象为卖点了。)

C++难学吗?能够靠读书、看文章、读代码、做练习学会的东西没什么门槛,智力正常的人只要愿意花工夫,都不难达到(不错)的程度。 ”C++好书很多,不过优秀的C++开源代码很少,而且风格迥异 。我这里按个人口味和经验列几个供读者参考阅读:GoogleprotobufleveldbPCREC++ 封装,我自己写的muduo网络库。这些代码都不长,功能明确,阅读难度不大。如果有时间,还可以读一读Chromium中的基础库源码。在读Google开源的C++代码时要连注释一起细读。我不建议一开始就读STLBoost的源码,因为编写通用C++模板库和编写C++应用程序的知识体系相差很大。另外可以考虑读一些优秀的CJava开源项目,并思考是否可以用C++更好地实现或封装之(特别是资源管理方面能否避免手动清理)。

继续前进

我能够随手列出十几本C++好书,但是从实用角度出发,这里只举两三本必读的书。读过《C++ Primer》和这几本书之后,想必读者已能自行识别C++图书的优劣,可以根据项目需要加以钻研。

第一本是《Effective C++(第3版)》 。学习语法是一回事,高效地运用这门语言是另一回事。C++是一个遍布陷阱的语言,吸取专家的经验尤为重要,既能快速提高眼界,又能避免重蹈覆辙。《C++ Primer》加上这本书包含的C++知识足以应付日常应用程序开发。

我假定读者一定会阅读这本书,因此在评注中不引用《Effective C++(第3版)》的任何章节。

Effective C++(第3版)》的内容也反映了C++用法的进步。第2版建议总是让基类拥有虚析构函数,第3版改为为多态基类声明虚析构函数。因为在C++中,继承不光只有面向对象这一种用途,即C++的继承不一定是为了覆写(override)基类的虚函数。第2版花了很多笔墨介绍浅拷贝与深拷贝,以及对指针成员变量的处理 。第3版则提议,对于多数class而言,要么直接禁用拷贝构造函数和赋值操作符;要么通过选用合适的成员变量类型 ,使得编译器默认生成的这两个成员函数就能正常工作。

什么是C++编程中最重要的编程技法(idiom)?我认为是用对象来管理资源,即RAII。资源包括动态分配的内存 ,也包括打开的文件、TCP网络连接、数据库连接、互斥锁等。借助RAII,我们可以把资源管理和对象生命期管理等同起来,而对象生命期管理在现代C++里根本不困难(见注3),只需要花几天时间熟悉几个智能指针 的基本用法即可。学会了这三招两式,现代的C++程序中可以完全不写delete,也不必为指针或内存错误操心。现代C++程序里出现资源和内存泄漏的唯一可能是循环引用,一旦发现,也很容易修正设计和代码。这方面的详细内容请参考《Effective C++(第3版)》的第3章(资源管理)。

C++是目前唯一能实现自动化资源管理的语言,C语言完全靠手工释放资源,而其他基于垃圾收集的语言只能自动清理内存,而不能自动清理其他资源 (网络连接、数据库连接等)。

除了智能指针,TR1中的bind/function也十分值得投入精力去学一学 。让你从一个崭新的视角,重新审视类与类之间的关系。Stephan T. Lavavej有一套PPT介绍TR1的这几个主要部件

第二本书,如果读者还是在校学生,已经学过数据结构课程 的话,可以考虑读一读《泛型编程与STL ;如果已经工作,学完《C++ Primer》立刻就要参加C++项目开发,那么我推荐阅读《C++编程规范》

泛型编程有一套自己的术语,如conceptmodelrefinement等,理解这套术语才能阅读泛型程序库的文档。即便不掌握泛型编程作为一种程序设计方法,也要掌握C++中以泛型思维设计出来的标准容器库和算法库(STL)。坊间面向对象的书琳琅满目,学习机会也很多,而泛型编程只有这么一本,读之可以开拓视野,并且可加深对STL的理解(特别是迭代器 )和应用。

C++模板是一种强大的抽象手段,我不赞同每个人都把精力花在钻研艰深的模板语法和技巧上。从实用角度,能在应用程序中写写简单的函数模板和类模板即可(以type traits为限),并非每个人都要去写公用的模板库。

由于C++语言过于庞大复杂,我见过的开发团队都对其剪裁使用 。往往团队越大,项目成立时间越早,剪裁得越厉害,也越接近C。制订一份好的编程规范相当不容易。若规范定得太紧(比如定为团队成员知识能力的交集),则程序员束手束脚,限制了生产力,对程序员个人发展也不利 。若规范定得太松(定为团队成员知识能力的并集),则项目内代码风格迥异,学习交流协作成本上升,恐怕对生产力也不利。由两位顶级专家合写的《C++编程规范》一书可谓是现代C++编程规范的范本。

C++编程规范》同时也是专家经验一类的书,这本书的篇幅比《Effective C++(第3版)》短小,条款数目却多了近一倍,可谓言简意赅。有的条款看了就明白,照做即可:

1条,以高警告级别编译代码,确保编译器无警告。

31条,避免写出依赖于函数实参求值顺序的代码。C++操作符的优先级、结合性与表达式的求值顺序是无关的。裘宗燕老师写的《C/C++语言中表达式的求值》 一文对此有明确的说明。

35条,避免继承并非设计作为基类使用class

43条,明智地使用pimpl。这是编写C++动态链接库的必备手法,可以最大限度地提高二进制兼容性。

56条,尽量提供不会失败的swap()函数。有了swap()函数,我们在自定义赋值操作符时就不必检查自赋值了。

59条,不要在头文件中或#include之前写using

73条,以by value方式抛出异常,以by reference方式捕捉异常。

76条,优先考虑vector,其次再选择适当的容器。

79条,容器内只可存放valuesmart pointer

有的条款则需要相当的设计与编码经验才能解其中三昧:

5条,为每个物体(entity)分配一个内聚任务。

6条,正确性、简单性、清晰性居首。

89条,不要过早优化;不要过早劣化。

22条,将依赖关系最小化。避免循环依赖。

32条,搞清楚你写的是哪一种class。明白value classbase classtrait classpolicy classexception class各有其作用,写法也不尽相同。

33条,尽可能写小型class,避免写出大怪兽

37条,public继承意味着可替换性。继承非为复用,乃为被复用。

57条,将class类型及其非成员函数接口放入同一个namespace

值得一提的是,《C++编程规范》是出发点,但不是一份终极规范。例如GoogleC++编程规范 LLVM编程规范 都明确禁用异常,这跟这本书的推荐做法正好相反。

评注版使用说明

评注版采用大16开印刷,在保留原书版式的前提下,对其进行了重新分页,评注的文字与正文左右分栏并列排版。另外,本书已依据原书2010年第11次印刷的版本进行了全面修订。为了节省篇幅,原书每章末尾的小结、术语表及书末的索引都没有印在评注版中,而是做成PDF供读者下载,这也方便读者检索。评注的目的是帮助初次学习C++的读者快速深入掌握这门语言的核心知识,澄清一些概念、比较与其他语言的不同、补充实践中的注意事项等。评注的内容约占全书篇幅的15%,大致比例是三分评、七分注,并有一些补白的内容 。如果读者拿不定主意是否购买,可以先翻一翻第5章。我在评注中不谈C++11 ,但会略微涉及TR1,因为TR1已经投入实用。

为了不打断读者阅读的思路,评注中不会给URL链接,评注中偶尔会引用《C++编程规范》的条款,以[CCS]标明,这些条款的标题已在前文列出。另外评注中出现的soXXXXXX表示http://stackoverflow.com/questions/XXXXXX网址。

网上资源

代码下载:http://www.informit.com/store/product.aspx?isbn=0201721481

豆瓣页面:http://book.douban.com/subject/10944985/

术语表与索引PDF下载:http://chenshuo.com/cp4(本序的电子版也发布于此,方便读者访问脚注中的网站)。

我的联系方式:giantchen@gmail.com

                            http://weibo.com/giantchen

陈硕

20125

中国香港

 

Preface          XXIV

Chapter 1 Getting Started (新增评注29 条)  

1.1 Writing a Simple C++Program . . . . . . . . . . . . . .

1.1.1 Compiling and Executing Our Program . . . . . .

1.2 AFirstLookat Input/Output . . . . . . . . . . . . . . . . .

1.2.1 StandardInput andOutputObjects . . . . . . . . . . .

1.2.2 AProgramthatUses the IOLibrary . . . . . . . . . . .

1.3 AWordAboutComments . . . . . . . . . . . . . . . . . . .

1.4 Control Structures . . . . . . . . . . . . . . . . . . . . . . . .

1.4.1 The whileStatement . . . . . . . . . . . . . . . . . . . . .

1.4.2 The forStatement . . . . . . . . . . . . . . . . . . . . . . .

1.4.3 The ifStatement . . . . . . . . . . . . . . . . . . . . . . . .

1.4.4 ReadinganUnknownNumberof Inputs . . . . . . .

1.5 IntroducingClasses . . . . . . . . . . . . . . . . . . . . . . .

1.5.1 The Sales_itemClass . . . . . . . . . . . . . . . . . . .

1.5.2 AFirstLookatMemberFunctions . . . . . . . . . . . ..

1.6 The C++Program . . . . . . . . . . . . . . . . . . . . . . .

 

Part I The Basics                               

Chapter 2 Variables and Basic Types(新增评注42 条)

2.1 PrimitiveBuilt-inTypes . . . . . . . . . . . . . . . . . . .

2.1.1 IntegralTypes . . . . . . . . . . . . . . . . . . . . . . . . .

2.1.2 Floating-PointTypes . . . . . . . . . . . . . . . . . . . .

2.2 LiteralConstants . . . . . . . . . . . . . . . . . . . . . . . .

2.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.3.1 What Is aVariable? . . . . . . . . . . . . . . . . . . . . .

2.3.2 TheNameof aVariable . . . . . . . . . . . . . . . . . .

2.3.3 DefiningObjects . . . . . . . . . . . . . . . . . . . . . . .

2.3.4 VariableInitializationRules . . . . . . . . . . . . . . .

2.3.5 Declarations andDefinitions . . . . . . . . . . . . .

2.3.6 Scopeof aName . . . . . . . . . . . . . . . . . . . . . . .

2.3.7 DefineVariablesWhereTheyAreUsed . . . . . .

2.4 constQualifier . . . . . . . . . . . . . . . . . . . . . . . . . .

2.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.6 TypedefNames . . . . . . . . . . . . . . . . . . . . . . . . .

2.7 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . .

2.8 ClassTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.9 Writing Our Own Header Files . . . . . . . . . . . . .

2.9.1 DesigningOurOwnHeaders . . . . . . . . . . . . . .

2.9.2 ABrief IntroductiontothePreprocessor . . . . . .

 

Chapter 3 Library Types (新增评注30 条)  

3.1 Namespace usingDeclarations . . . . . . . . . . . . . . 

3.2 Library stringType . . . . . . . . . . . . . . . . . . . . . . .

3.2.1 Defining and Initializing strings . . . . . . . . . . .

3.2.2 Reading andWriting strings . . . . . . . . . . . . . .

3.2.3 Operations on strings . . . . . . . . . . . . . . . . . . .

3.2.4 Dealing with the Characters of a string . . . . .

3.3 Library vectorType . . . . . . . . . . . . . . . . . . . . . .

3.3.1 Defining and Initializing vectors . . . . . . . . . .

3.3.2 Operations on vectors . . . . . . . . . . . . . . . . . . .

3.4 IntroducingIterators . . . . . . . . . . . . . . . . . . . . . .

3.4.1 IteratorArithmetic . . . . . . . . . . . . . . . . . . . . . .

3.5 Library bitsetType . . . . . . . . . . . . . . . . . . . . . . .

3.5.1 Defining and Initializing bitsets . . . . . . . . . . .

3.5.2 Operations on bitsets . . . . . . . . . . . . . . . . . . . 

 

Chapter 4 Arrays and Pointers (新增评注33 条)

4.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.1.1 DefiningandInitializingArrays . . . . . . . . . . . . .

4.1.2 OperationsonArrays . . . . . . . . . . . . . . . . . . . . .

4.2 IntroducingPointers . . . . . . . . . . . . . . . . . . . . . . .

4.2.1 What Is aPointer? . . . . . . . . . . . . . . . . . . . . . . .

4.2.2 DefiningandInitializingPointers . . . . . . . . . . . .

4.2.3 OperationsonPointers . . . . . . . . . . . . . . . . . . . .

4.2.4 UsingPointers toAccessArrayElements . . . . . .

4.2.5 Pointers and the constQualifier . . . . . . . . . . . .

4.3 C-StyleCharacterStrings . . . . . . . . . . . . . . . . . .

4.3.1 DynamicallyAllocatingArrays . . . . . . . . . . .

4.3.2 InterfacingtoOlderCode . . . . . . . . . . . . . . . .

4.4 MultidimensionedArrays . . . . . . . . . . . . . . . . . .

4.4.1 Pointers andMultidimensionedArrays . . . . . .

 

Chapter 5 Expressions (新增评注49 条)   

5.1 ArithmeticOperators . . . . . . . . . . . . . . . . . . . . .

5.2 Relational andLogicalOperators . . . . . . . . . . . .

5.3 TheBitwiseOperators . . . . . . . . . . . . . . . . . . . .

5.3.1 Using bitsetObjectsor IntegralValues . . . . . .

5.3.2 Usingthe ShiftOperators for IO . . . . . . . . . . .

5.4 AssignmentOperators . . . . . . . . . . . . . . . . . . .

5.4.1 Assignment IsRightAssociative . . . . . . . . . . .

5.4.2 AssignmentHasLowPrecedence . . . . . . . . . .

5.4.3 CompoundAssignmentOperators . . . . . . . . .

5.5 Increment andDecrementOperators . . . . . . . . .

5.6 TheArrowOperator . . . . . . . . . . . . . . . . . . . . . .

5.7 TheConditionalOperator . . . . . . . . . . . . . . . . . .

5.8 The sizeofOperator . . . . . . . . . . . . . . . . . . . . . .

5.9 CommaOperator . . . . . . . . . . . . . . . . . . . . . . . .

5.10 EvaluatingCompoundExpressions . . . . . . . . .

5.10.1 Precedence . . . . . . . . . . . . . . . . . . . . . . . . . .

5.10.2 Associativity . . . . . . . . . . . . . . . . . . . . . . . . .

5.10.3 OrderofEvaluation . . . . . . . . . . . . . . . . . . . .

5.11 The new and deleteExpressions . . . . . . . . . . .

5.12 TypeConversions . . . . . . . . . . . . . . . . . . . . . . .

5.12.1 WhenImplicitTypeConversionsOccur . . . . .

5.12.2 TheArithmeticConversions . . . . . . . . . . . . .

5.12.3 Other ImplicitConversions . . . . . . . . . . . . . .

5.12.4 ExplicitConversions . . . . . . . . . . . . . . . . . . .

5.12.5 WhenCastsMightBeUseful . . . . . . . . . . . . . .

5.12.6 NamedCasts . . . . . . . . . . . . . . . . . . . . . . . . .

5.12.7 Old-StyleCasts . . . . . . . . . . . . . . . . . . . . . . .

 

Chapter 6 Statements (新增评注29 条)   

6.1 Simple Statements . . . . . . . . . . . . . . . . . . . . .

6.2 DeclarationStatements . . . . . . . . . . . . . . . . . .

6.3 CompoundStatements (Blocks) . . . . . . . . . . .

6.4 StatementScope . . . . . . . . . . . . . . . . . . . . . . .

6.5 The ifStatement . . . . . . . . . . . . . . . . . . . . . . .

6.5.1 The if Statement elseBranch . . . . . . . . . . . .

6.6 The switchStatement . . . . . . . . . . . . . . . . . . .

6.6.1 Using a switch . . . . . . . . . . . . . . . . . . . . . .

6.6.2 Control Flow within a switch . . . . . . . . . . .

6.6.3 The defaultLabel . . . . . . . . . . . . . . . . . . . . .

6.6.4 switchExpressionandCaseLabels . . . . . . . .

6.6.5 Variable Definitions inside a switch . . . . . .

6.7 The whileStatement . . . . . . . . . . . . . . . . . . . .

6.8 The forLoopStatement . . . . . . . . . . . . . . . . . .

6.8.1 Omitting Parts of the forHeader . . . . . . . . .

6.8.2 Multiple Definitions in the forHeader . . . .

6.9 The do whileStatement . . . . . . . . . . . . . . . . .

6.10 The breakStatement . . . . . . . . . . . . . . . . . . .

6.11 The continueStatement . . . . . . . . . . . . . . . . .

6.12 The gotoStatement . . . . . . . . . . . . . . . . . . . .

6.13 tryBlocks andExceptionHandling . . . . . . . .

6.13.1 A throwExpression . . . . . . . . . . . . . . . . . . . .

6.13.2 The tryBlock . . . . . . . . . . . . . . . . . . . . . . . .

6.13.3 StandardExceptions . . . . . . . . . . . . . . . . . . .

6.14 Using the Preprocessor for Debugging . . . . .

 

Chapter 7 Functions (新增评注56 条)    

7.1 DefiningaFunction . . . . . . . . . . . . . . . . . . . . . .

7.1.1 FunctionReturnType . . . . . . . . . . . . . . . . . . .

7.1.2 FunctionParameterList . . . . . . . . . . . . . . . . .

7.2 ArgumentPassing . . . . . . . . . . . . . . . . . . . . . . .

7.2.1 NonreferenceParameters . . . . . . . . . . . . . . . .

7.2.2 ReferenceParameters . . . . . . . . . . . . . . . . . . .

7.2.3 vectorandOtherContainerParameters . . . . . .

7.2.4 ArrayParameters . . . . . . . . . . . . . . . . . . . . . .

7.2.5 ManagingArraysPassedtoFunctions . . . . . . .

7.2.6 main:HandlingCommand-LineOptions . . . . .

7.2.7 FunctionswithVaryingParameters . . . . . . . . .

7.3 The returnStatement . . . . . . . . . . . . . . . . . . . . .

7.3.1 FunctionswithNoReturnValue . . . . . . . . . . . .

7.3.2 Functions thatReturnaValue . . . . . . . . . . . . .

7.3.3 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . .

7.4 FunctionDeclarations . . . . . . . . . . . . . . . . . . . .

7.4.1 DefaultArguments . . . . . . . . . . . . . . . . . . . . .

7.5 LocalObjects . . . . . . . . . . . . . . . . . . . . . . . . . .

7.5.1 AutomaticObjects . . . . . . . . . . . . . . . . . . . . .

7.5.2 StaticLocalObjects . . . . . . . . . . . . . . . . . . . .

7.6 Inline Functions . . . . . . . . . . . . . . . . . . . . . . . .

7.7 ClassMemberFunctions . . . . . . . . . . . . . . . . . .

7.7.1 DefiningtheBodyofaMemberFunction . . . . .

7.7.2 DefiningaMemberFunctionOutside theClass . .

7.7.3 Writing the Sales_itemConstructor . . . . . . . . .

7.7.4 Organizing Class Code Files . . . . . . . . . . . . . .

7.8 OverloadedFunctions . . . . . . . . . . . . . . . . . . . . .

7.8.1 OverloadingandScope . . . . . . . . . . . . . . . . . . .

7.8.2 FunctionMatchingandArgumentConversions .

7.8.3 TheThreeSteps inOverloadResolution . . . . . . .

7.8.4 Argument-TypeConversions . . . . . . . . . . . . . .

7.9 Pointers toFunctions . . . . . . . . . . . . . . . . . . . . . .

 

Chapter 8 The IO Library(新增评注11 条) 

8.1 AnObject-OrientedLibrary . . . . . . . . . . . . . . .

8.2 Condition States . . . . . . . . . . . . . . . . . . . . .

8.3 ManagingtheOutputBuffer . . . . . . . . . . . . . . .

8.4 File Input and Output . . . . . . . . . . . . . . . . . .

8.4.1 Using File Stream Objects . . . . . . . . . . . . .

8.4.2 File Modes . . . . . . . . . . . . . . . . . . . . . . . .

8.4.3 A Program to Open and Check Input Files .

8.5 StringStreams . . . . . . . . . . . . . . . . . . . . . . . .

 

Part II Containers and Algorithms          

Chapter 9 Sequential Containers (新增评注54 条)

9.1 Defininga SequentialContainer . . . . . . . . . . . . . .

9.1.1 InitializingContainerElements . . . . . . . . . . . . .

9.1.2 Constraints onTypes that aContainerCanHold .

9.2 Iterators andIteratorRanges . . . . . . . . . . . . . . . . .

9.2.1 IteratorRanges . . . . . . . . . . . . . . . . . . . . . . . . .

9.2.2 SomeContainerOperations InvalidateIterators .

9.3 SequenceContainerOperations . . . . . . . . . . . . . .

9.3.1 ContainerTypedefs . . . . . . . . . . . . . . . . . . . . . .

9.3.2 begin and endMembers . . . . . . . . . . . . . . . . . .

9.3.3 AddingElements toaSequentialContainer . . . .

9.3.4 RelationalOperators . . . . . . . . . . . . . . . . . . . . .

9.3.5 Container SizeOperations . . . . . . . . . . . . . . . .

9.3.6 AccessingElements . . . . . . . . . . . . . . . . . . . . .

9.3.7 ErasingElements . . . . . . . . . . . . . . . . . . . . . . .

9.3.8 Assignment and swap . . . . . . . . . . . . . . . . . . .

9.4 How a vectorGrows . . . . . . . . . . . . . . . . . . . . . .

9.4.1 capacity and reserveMembers . . . . . . . . . . . . .

9.5 DecidingWhichContainer toUse . . . . . . . . . . . . .

9.6 stringsRevisited . . . . . . . . . . . . . . . . . . . . . . . . . .

9.6.1 Other Ways to Construct strings . . . . . . . . .

9.6.2 Other Ways to Change a string . . . . . . . . . .

9.6.3 string-OnlyOperations . . . . . . . . . . . . . . . . .

9.6.4 stringSearchOperations . . . . . . . . . . . . . . . .

9.6.5 Comparing strings . . . . . . . . . . . . . . . . . . . .

9.7 ContainerAdaptors . . . . . . . . . . . . . . . . . . . . .

9.7.1 StackAdaptor . . . . . . . . . . . . . . . . . . . . . . . .

9.7.2 Queue andPriorityQueue . . . . . . . . . . . . . . .

 

Chapter 10 Associative Containers (新增评注22 条) 

10.1 Preliminaries: the pairType . . . . . . . . . . . . .

10.2 AssociativeContainers . . . . . . . . . . . . . . . .

10.3 The mapType . . . . . . . . . . . . . . . . . . . . . . .

10.3.1 Defining a map . . . . . . . . . . . . . . . . . . . .

10.3.2 Types Defined by map . . . . . . . . . . . . . . .

10.3.3 Adding Elements to a map . . . . . . . . . . .

10.3.4 Subscripting a map . . . . . . . . . . . . . . . . .

10.3.5 Using map::insert . . . . . . . . . . . . . . . . .

10.3.6 Finding and Retrieving a mapElement . .

10.3.7 Erasing Elements from a map . . . . . . . .

10.3.8 Iterating across a map . . . . . . . . . . . . . . .

10.3.9 AWordTransformationMap . . . . . . . . . . .

10.4 The setType . . . . . . . . . . . . . . . . . . . . . . . .

10.4.1 Defining and Using sets . . . . . . . . . . . . . . . .

10.4.2 BuildingaWord-ExclusionSet . . . . . . . . . . .

10.5 The multimap and multisetTypes . . . . . . . .

10.5.1 AddingandRemovingElements . . . . . . . . . . .

10.5.2 Finding Elements in a multimap or multiset .

10.6 UsingContainers: Text-QueryProgram . . . . . . .

10.6.1 Designof theQueryProgram . . . . . . . . . . . . . .

10.6.2 TextQueryClass . . . . . . . . . . . . . . . . . . . . . . .

10.6.3 Using the TextQueryClass . . . . . . . . . . . . . . .

10.6.4 WritingtheMemberFunctions . . . . . . . . . . . . .

 

Chapter 11 Generic Algorithms (新增评注18 条)

11.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . .

11.2 AFirstLookat theAlgorithms . . . . . . . . . . . . . . . .

11.2.1 Read-OnlyAlgorithms . . . . . . . . . . . . . . . . .

11.2.2 Algorithms thatWriteContainerElements . . .

11.2.3 Algorithms thatReorderContainerElements .

11.3 Revisiting Iterators . . . . . . . . . . . . . . . . . . . .

11.3.1 Insert Iterators . . . . . . . . . . . . . . . . . . . . . .

11.3.2 iostream Iterators . . . . . . . . . . . . . . . . . . . .

11.3.3 Reverse Iterators . . . . . . . . . . . . . . . . . . . .

11.3.4 const Iterators . . . . . . . . . . . . . . . . . . . . . .

11.3.5 TheFive IteratorCategories . . . . . . . . . . . .

11.4 StructureofGenericAlgorithms . . . . . . . . . . .

11.4.1 AlgorithmParameterPatterns . . . . . . . . . . .

11.4.2 AlgorithmNamingConventions . . . . . . . . .

11.5 Container-SpecificAlgorithms . . . . . . . . . . .

 

Part III Classes and Data Abstraction         

Chapter 12 Classes 429(新增评注26 条) 

12.1 ClassDefinitions andDeclarations . . . . . . . .

12.1.1 ClassDefinitions: ARecap . . . . . . . . . . .

12.1.2 DataAbstractionandEncapsulation . . . . .

12.1.3 MoreonClassDefinitions . . . . . . . . . . . . . .

12.1.4 ClassDeclarationsversusDefinitions . . . . .

12.1.5 ClassObjects . . . . . . . . . . . . . . . . . . . . . . .

12.2 The Implicit thisPointer . . . . . . . . . . . . . . . .

12.3 ClassScope . . . . . . . . . . . . . . . . . . . . . . . . .

12.3.1 NameLookupinClassScope . . . . . . . . . . .

12.4 Constructors . . . . . . . . . . . . . . . . . . . . . . . .

12.4.1 TheConstructor Initializer . . . . . . . . . . . .

12.4.2 DefaultArguments andConstructors . . . . .

12.4.3 TheDefaultConstructor . . . . . . . . . . . . . . .

12.4.4 ImplicitClass-TypeConversions . . . . . . .

12.4.5 Explicit InitializationofClassMembers . . .

12.5 Friends . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12.6 staticClassMembers . . . . . . . . . . . . . . . . . . .

12.6.1 staticMemberFunctions . . . . . . . . . . . . . . . . . . .

12.6.2 staticDataMembers . . . . . . . . . . . . . . . . . . . . .

 

Chapter 13 Copy Control (新增评注30 条)  

13.1 TheCopyConstructor . . . . . . . . . . . . . . . . . . .

13.1.1 The SynthesizedCopyConstructor . . . . . . .

13.1.2 DefiningOurOwnCopyConstructor . . . . . . .

13.1.3 PreventingCopies . . . . . . . . . . . . . . . . . . . .

13.2 TheAssignmentOperator . . . . . . . . . . . . . . . .

13.3 TheDestructor . . . . . . . . . . . . . . . . . . . . . . . .

13.4 AMessage-HandlingExample . . . . . . . . . . . .

13.5 ManagingPointerMembers . . . . . . . . . . . . . . .

13.5.1 DefiningSmartPointerClasses . . . . . . . . . . .

13.5.2 Defining Valuelike Classes . . . . . . . . . . . . .

 

Chapter 14 Overloaded Operations and Conversions (新增评注31 条)

14.1 DefininganOverloadedOperator . . . . . . . . . . .

14.1.1 OverloadedOperatorDesign . . . . . . . . . .

14.2 Input andOutputOperators . . . . . . . . . . . . .

14.2.1 Overloading the Output Operator << . . .

14.2.2 Overloading the Input Operator >> . . . .

14.3 Arithmetic andRelationalOperators . . . . .

14.3.1 EqualityOperators . . . . . . . . . . . . . . . . . .

14.3.2 RelationalOperators . . . . . . . . . . . . . . . .

14.4 AssignmentOperators . . . . . . . . . . . . . . . . .

14.5 SubscriptOperator . . . . . . . . . . . . . . . . . . .

14.6 MemberAccessOperators . . . . . . . . . . . . . .

14.7 Increment andDecrementOperators . . . . .

14.8 CallOperatorandFunctionObjects . . . . . . . . . . . .

14.8.1 UsingFunctionObjectswithLibraryAlgorithms .

14.8.2 Library-DefinedFunctionObjects . . . . . . . . . .

14.8.3 FunctionAdaptors forFunctionObjects . . . . . .

14.9 Conversions andClassTypes . . . . . . . . . . . . . . .

14.9.1 WhyConversionsAreUseful . . . . . . . . . . . . . .

14.9.2 ConversionOperators . . . . . . . . . . . . . . . . . . .

14.9.3 ArgumentMatchingandConversions . . . . . . . .

14.9.4 OverloadResolution andClassArguments . . .

14.9.5 Overloading,Conversions, andOperators . . . .

 

Part IV Object-Oriented and Generic Programming  

Chapter 15 Object-Oriented Programming (新增评注56 条)

15.1 OOP:AnOverview . . . . . . . . . . . . . . . . . . . . . . .

15.2 DefiningBaseandDerivedClasses . . . . . . . . . . .

15.2.1 DefiningaBaseClass . . . . . . . . . . . . . . . . . . . .

15.2.2 protectedMembers . . . . . . . . . . . . . . . . . .

15.2.3 DerivedClasses . . . . . . . . . . . . . . . . . . . . .

15.2.4 virtualandOtherMemberFunctions . . . . . .

15.2.5 Public,Private,andProtectedInheritance . .

15.2.6 FriendshipandInheritance . . . . . . . . . . . . .

15.2.7 Inheritance andStaticMembers . . . . . . . . .

15.3 Conversions andInheritance . . . . . . . . . . . . .

15.3.1 Derived-to-BaseConversions . . . . . . . . . .

15.3.2 Conversions fromBasetoDerived . . . . . . .

15.4 Constructors andCopyControl . . . . . . . . . . .

15.4.1 Base-ClassConstructors andCopyControl .

15.4.2 Derived-ClassConstructors . . . . . . . . . . . .

15.4.3 CopyControl andInheritance . . . . . . . . . .

15.4.4 VirtualDestructors . . . . . . . . . . . . . . . . . .

15.4.5 Virtuals inConstructors andDestructors . .

15.5 ClassScopeunder Inheritance . . . . . . . . . . .

15.5.1 NameLookupHappensatCompileTime . .

15.5.2 Name Collisions and Inheritance . . . . . . .

15.5.3 ScopeandMemberFunctions . . . . . . . . . .

15.5.4 VirtualFunctions andScope . . . . . . . . . . .

15.6 PureVirtualFunctions . . . . . . . . . . . . . . . . .

15.7 Containers andInheritance . . . . . . . . . . . . .

15.8 HandleClassesandInheritance . . . . . . . . . . .

15.8.1 A Pointerlike Handle . . . . . . . . . . . . . . . .

15.8.2 CloninganUnknownType . . . . . . . . . . . . .

15.8.3 UsingtheHandle . . . . . . . . . . . . . . . . . . . .

15.9 TextQueriesRevisited . . . . . . . . . . . . . . . . .

15.9.1 AnObject-OrientedSolution . . . . . . . . . . .

15.9.2 A Valuelike Handle . . . . . . . . . . . . . . . . .

15.9.3 The Query_baseClass . . . . . . . . . . . . . . .

15.9.4 The QueryHandleClass . . . . . . . . . . . . . .

15.9.5 TheDerivedClasses . . . . . . . . . . . . . . . . .

15.9.6 The evalFunctions . . . . . . . . . . . . . . . . . .

 

Chapter 16 Templates and Generic Programming (新增评注31 条)

16.1 TemplateDefinitions . . . . . . . . . . . . . . . . . . . .

16.1.1 DefiningaFunctionTemplate . . . . . . . . . . . .

16.1.2 DefiningaClassTemplate . . . . . . . . . . . . . .

16.1.3 TemplateParameters . . . . . . . . . . . . . . . . . .

16.1.4 TemplateTypeParameters . . . . . . . . . . . . .

16.1.5 NontypeTemplateParameters . . . . . . . . . . . .

16.1.6 WritingGenericPrograms . . . . . . . . . . . . . . .

16.2 Instantiation . . . . . . . . . . . . . . . . . . . . . . . . . .

16.2.1 TemplateArgumentDeduction . . . . . . . . . .

16.2.2 Function-TemplateExplicitArguments . . . .

16.3 TemplateCompilationModels . . . . . . . . . . . . .

16.4 ClassTemplateMembers . . . . . . . . . . . . . . . . .

16.4.1 Class-TemplateMemberFunctions . . . . . . . .

16.4.2 TemplateArguments forNontypeParameters

16.4.3 FriendDeclarations inClassTemplates . . . . .

16.4.4 Queue and QueueItemFriendDeclarations .

16.4.5 MemberTemplates . . . . . . . . . . . . . . . . . . . .

16.4.6 The Complete QueueClass . . . . . . . . . . . .

16.4.7 staticMembersofClassTemplates . . . . . . . . .

16.5 AGenericHandleClass . . . . . . . . . . . . . . . . .

16.5.1 DefiningtheHandleClass . . . . . . . . . . . . . . .

16.5.2 UsingtheHandle . . . . . . . . . . . . . . . . . . . . . .

16.6 Template Specializations . . . . . . . . . . . . . . . .

16.6.1 SpecializingaFunctionTemplate . . . . . . .

16.6.2 SpecializingaClassTemplate . . . . . . . . . . . .

16.6.3 SpecializingMembersbutNot theClass . . . .

16.6.4 Class-TemplatePartialSpecializations . . . . .

16.7 OverloadingandFunctionTemplates . . . . . . . .

 

Part V Advanced Topics                    

Chapter 17 Tools for Large Programs (新增评注37 条) 

17.1 ExceptionHandling . . . . . . . . . . . . . . . . . . . .

17.1.1 ThrowinganExceptionofClassType . . . . .

17.1.2 StackUnwinding . . . . . . . . . . . . . . . . . . . .

17.1.3 CatchinganException . . . . . . . . . . . . . . . .

17.1.4 Rethrow . . . . . . . . . . . . . . . . . . . . . . . . . .

17.1.5 TheCatch-AllHandler . . . . . . . . . . . . . . . .

17.1.6 FunctionTryBlocks andConstructors . . . .

17.1.7 ExceptionClassHierarchies . . . . . . . . . . .

17.1.8 AutomaticResourceDeallocation . . . . . . .

17.1.9 The auto_ptrClass . . . . . . . . . . . . . . . . . .

17.1.10ExceptionSpecifications . . . . . . . . . . . . .

17.1.11FunctionPointerExceptionSpecifications

17.2 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . .

17.2.1 NamespaceDefinitions . . . . . . . . . . . . . . .

17.2.2 NestedNamespaces . . . . . . . . . . . . . . . . .

17.2.3 UnnamedNamespaces . . . . . . . . . . . . . . .

17.2.4 UsingNamespaceMembers . . . . . . . . . . .

17.2.5 Classes,Namespaces,andScope . . . . . . . .

17.2.6 OverloadingandNamespaces . . . . . . . . . .

17.2.7 NamespacesandTemplates . . . . . . . . . . . .

17.3 Multiple andVirtual Inheritance . . . . . . . . .

17.3.1 Multiple Inheritance . . . . . . . . . . . . . . . . .

17.3.2 Conversions andMultipleBaseClasses . . . . . .

17.3.3 CopyControl forMultiplyDerivedClasses . . .

17.3.4 ClassScopeunderMultiple Inheritance . . . . . .

17.3.5 Virtual Inheritance . . . . . . . . . . . . . . . . . . . . .

17.3.6 VirtualBaseClassDeclaration . . . . . . . . . . . . .

17.3.7 Special InitializationSemantics . . . . . . . . . . .

 

Chapter 18 Specialized Tools and Techniques (新增评注22 条) 

18.1 OptimizingMemoryAllocation . . . . . . . . . . . .

18.1.1 Memory Allocation in C++ . . . . . . . . . . . . .

18.1.2 The allocatorClass . . . . . . . . . . . . . . . . . . . .

18.1.3 operator new and operator deleteFunctions .

18.1.4 Placement newExpressions . . . . . . . . . . . . .

18.1.5 ExplicitDestructor Invocation . . . . . . . . . . .

18.1.6 Class Specific new and delete . . . . . . . . . . .

18.1.7 AMemory-AllocatorBaseClass . . . . . . . . . .

18.2 Run-TimeTypeIdentification . . . . . . . . . . . . . .

18.2.1 The dynamic_castOperator . . . . . . . . . . . . .

18.2.2 The typeidOperator . . . . . . . . . . . . . . . . . .

18.2.3 UsingRTTI . . . . . . . . . . . . . . . . . . . . . . . .

18.2.4 The type_infoClass . . . . . . . . . . . . . . . . . .

18.3 Pointer toClassMember . . . . . . . . . . . . . . . .

18.3.1 DeclaringaPointer toMember . . . . . . . . . .

18.3.2 UsingaPointer toClassMember . . . . . . . . .

18.4 NestedClasses . . . . . . . . . . . . . . . . . . . . . . .

18.4.1 ANested-Class Implementation . . . . . . . .

18.4.2 NameLookupinNestedClassScope . . . . . .

18.5 Union: ASpace-SavingClass . . . . . . . . . . . .

18.6 LocalClasses . . . . . . . . . . . . . . . . . . . . . . . .

18.7 InherentlyNonportableFeatures . . . . . . . . . .

18.7.1 Bit-fields . . . . . . . . . . . . . . . . . . . . . . . . . . . .

18.7.2 volatileQualifier . . . . . . . . . . . . . . . . . . . . . .

18.7.3 Linkage Directives: extern "C" . . . . . . . . . . .

 

Appendix A The Library                    

A.1 LibraryNames andHeaders . . . . . . . . . . . . . . . .

A.2 ABriefTourof theAlgorithms . . . . . . . . . . . . . .

A.2.1 Algorithms toFindanObject . . . . . . . . . . . . .

A.2.2 OtherRead-OnlyAlgorithms . . . . . . . . . . . .

A.2.3 Binary-SearchAlgorithms . . . . . . . . . . . . . .

A.2.4 Algorithms thatWriteContainerElements . . . .

A.2.5 PartitioningandSortingAlgorithms . . . . . . . . .

A.2.6 GeneralReorderingOperations . . . . . . . . . . . .

A.2.7 PermutationAlgorithms . . . . . . . . . . . . . . . . .

A.2.8 SetAlgorithms for SortedSequences . . . . . . .

A.2.9 MinimumandMaximumValues . . . . . . . . . . .

A.2.10 NumericAlgorithms . . . . . . . . . . . . . . . . . .

A.3 The IOLibraryRevisited . . . . . . . . . . . . . . . . . .

A.3.1 FormatState . . . . . . . . . . . . . . . . . . . . . . . . . .

A.3.2 ManyManipulatorsChangetheFormatState. .

A.3.3 Controlling Output Formats . . . . . . . . . . . . .

A.3.4 Controlling Input Formatting . . . . . . . . . . . .

A.3.5 UnformattedInput/OutputOperations . . . . . .

A.3.6 Single-ByteOperations . . . . . . . . . . . . . . . . .

A.3.7 Multi-ByteOperations . . . . . . . . . . . . . . . . . .

A.3.8 RandomAccess toaStream . . . . . . . . . . . . . .

A.3.9 Reading andWriting to the Same File . . . . . .

阅读(1074) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~