C++ Primer 英文版(第 5 版)

0
(0)

C++ Primer 英文版(第 5 版)

作者:[美]StanleyB.Lippman/[美]JoséeLajoie/[美]BarbaraE.Moo

出版社:电子工业出版社

出品方:博文视点

原作名:C++Primer,5thEdition

出版年:2013-5-1

页数:938

定价:128.00元

装帧:平装

ISBN:9787121200380

内容简介
······

这本久负盛名的C++经典教程,时隔八年之久,终迎来史无前例的重大升级。除令全球无数程序员从中受益,甚至为之迷醉的——C++大师Stanley B. Lippman的丰富实践经验,C++标准委员会原负责人Josée Lajoie对C++标准的深入理解,以及C++先驱Barbara E. Moo在C++教学方面的真知灼见外,更是基于全新的C++11标准进行了全面而彻底的内容更新。非常难能可贵的是,书中所有示例均全部采用C++11标准改写,这在经典升级版中极其罕见——充分体现了C++语言的重大进展极其全面实践。书中丰富的教学辅助内容、醒目的知识点提示,以及精心组织的编程示范,让这本书在C++领域的权威地位更加不可动摇。无论是初学者入门,或是中、高级程序员提升,本书均为不容置疑的首选。

作者简介
······

Stanley B. Lippman目前是微软公司 Visual C++ 团队的架构师。他从1984年开始在贝尔实验室与C++的设计者Bjarne Stroustrup一起从事C++的设计与开发。他在迪士尼和梦工厂从事动画制作,还担任过JPL的高级顾问。

Josée Lajoie曾经是IBM加拿大研究中心C/C++编译器开发团队的成员,在ISO C++标准委员会工作了7年,担任过ISO核心语言工作组的主席和C++ Report杂志的专栏作家。

Barbara E. Moo是拥有25年软件经验的独立咨询顾问。在AT&T,她与Stroustrup、Lippman一起管理过复杂的C++开发项目。

目录
······

Preface xxiii

Chapter 1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

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

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

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

1.3 AWordaboutComments . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.4 FlowofControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

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

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

1.4.3 ReadinganUnknownNumberof Inputs . . . . . . . . . . . . 14

1.4.4 The ifStatement . . . . . . . . . . . . . . . . . . . . . . . . . . 17

1.5 IntroducingClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

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

1.5.2 AFirstLookatMemberFunctions . . . . . . . . . . . . . . . . 23

1.6 TheBookstoreProgram. . . . . . . . . . . . . . . . . . . . . . . . . . . 24

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Part I The Basics 29

Chapter 2 Variables and Basic Types . . . . . . . . . . . . . . . . . . . . . 31

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

2.1.1 ArithmeticTypes . . . . . . . . . . . . . . . . . . . . . . . . . . 32

2.1.2 TypeConversions . . . . . . . . . . . . . . . . . . . . . . . . . . 35

2.1.3 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

2.2 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

2.2.1 VariableDefinitions . . . . . . . . . . . . . . . . . . . . . . . . 41

2.2.2 VariableDeclarations andDefinitions . . . . . . . . . . . . . . 44

2.2.3 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

2.2.4 Scopeof aName . . . . . . . . . . . . . . . . . . . . . . . . . . 48

2.3 CompoundTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

2.3.1 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

2.3.2 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

vii

viii Contents

2.3.3 UnderstandingCompoundTypeDeclarations . . . . . . . . . 57

2.4 constQualifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

2.4.1 References to const . . . . . . . . . . . . . . . . . . . . . . . . 61

2.4.2 Pointers and const . . . . . . . . . . . . . . . . . . . . . . . . 62

2.4.3 Top-Level const . . . . . . . . . . . . . . . . . . . . . . . . . . 63

2.4.4 constexprandConstantExpressions . . . . . . . . . . . . . 65

2.5 DealingwithTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

2.5.1 TypeAliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

2.5.2 The autoTypeSpecifier . . . . . . . . . . . . . . . . . . . . . . 68

2.5.3 The decltypeTypeSpecifier . . . . . . . . . . . . . . . . . . . 70

2.6 DefiningOurOwnDataStructures . . . . . . . . . . . . . . . . . . . . 72

2.6.1 Defining the Sales_dataType . . . . . . . . . . . . . . . . . 72

2.6.2 Using the Sales_dataClass . . . . . . . . . . . . . . . . . . . 74

2.6.3 Writing Our Own Header Files . . . . . . . . . . . . . . . . . . 76

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

Chapter 3 Strings, Vectors, and Arrays . . . . . . . . . . . . . . . . . . . . 81

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

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

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

3.2.2 Operations on strings . . . . . . . . . . . . . . . . . . . . . . 85

3.2.3 Dealing with the Characters in a string . . . . . . . . . . . . 90

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

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

3.3.2 Adding Elements to a vector . . . . . . . . . . . . . . . . . . 100

3.3.3 Other vectorOperations . . . . . . . . . . . . . . . . . . . . . 102

3.4 IntroducingIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

3.4.1 UsingIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

3.4.2 IteratorArithmetic . . . . . . . . . . . . . . . . . . . . . . . . . 111

3.5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

3.5.1 DefiningandInitializingBuilt-inArrays . . . . . . . . . . . . 113

3.5.2 AccessingtheElementsof anArray . . . . . . . . . . . . . . . 116

3.5.3 Pointers andArrays . . . . . . . . . . . . . . . . . . . . . . . . 117

3.5.4 C-StyleCharacterStrings . . . . . . . . . . . . . . . . . . . . . 122

3.5.5 InterfacingtoOlderCode . . . . . . . . . . . . . . . . . . . . . 124

3.6 MultidimensionalArrays . . . . . . . . . . . . . . . . . . . . . . . . . 125

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

Chapter 4 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

4.1 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

4.1.1 BasicConcepts . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

4.1.2 PrecedenceandAssociativity . . . . . . . . . . . . . . . . . . . 136

4.1.3 OrderofEvaluation . . . . . . . . . . . . . . . . . . . . . . . . 137

4.2 ArithmeticOperators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

4.3 Logical andRelationalOperators . . . . . . . . . . . . . . . . . . . . . 141

Contents ix

4.4 AssignmentOperators . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

4.5 Increment andDecrementOperators . . . . . . . . . . . . . . . . . . . 147

4.6 TheMemberAccessOperators . . . . . . . . . . . . . . . . . . . . . . 150

4.7 TheConditionalOperator . . . . . . . . . . . . . . . . . . . . . . . . . 151

4.8 TheBitwiseOperators . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

4.9 The sizeofOperator . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

4.10 CommaOperator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

4.11 TypeConversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

4.11.1 TheArithmeticConversions . . . . . . . . . . . . . . . . . . . 159

4.11.2 Other ImplicitConversions . . . . . . . . . . . . . . . . . . . . 161

4.11.3 ExplicitConversions . . . . . . . . . . . . . . . . . . . . . . . . 162

4.12 OperatorPrecedenceTable . . . . . . . . . . . . . . . . . . . . . . . . . 166

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

Chapter 5 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

5.1 Simple Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

5.2 StatementScope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

5.3 Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

5.3.1 The ifStatement . . . . . . . . . . . . . . . . . . . . . . . . . . 175

5.3.2 The switchStatement . . . . . . . . . . . . . . . . . . . . . . . 178

5.4 IterativeStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

5.4.1 The whileStatement . . . . . . . . . . . . . . . . . . . . . . . 183

5.4.2 Traditional forStatement . . . . . . . . . . . . . . . . . . . . . 185

5.4.3 Range forStatement . . . . . . . . . . . . . . . . . . . . . . . 187

5.4.4 The do whileStatement . . . . . . . . . . . . . . . . . . . . . 189

5.5 JumpStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

5.5.1 The breakStatement . . . . . . . . . . . . . . . . . . . . . . . 190

5.5.2 The continueStatement . . . . . . . . . . . . . . . . . . . . . 191

5.5.3 The gotoStatement . . . . . . . . . . . . . . . . . . . . . . . . 192

5.6 tryBlocks andExceptionHandling . . . . . . . . . . . . . . . . . . . 193

5.6.1 A throwExpression . . . . . . . . . . . . . . . . . . . . . . . . 193

5.6.2 The tryBlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

5.6.3 StandardExceptions . . . . . . . . . . . . . . . . . . . . . . . . 197

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

Chapter 6 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

6.1 FunctionBasics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

6.1.1 LocalObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

6.1.2 FunctionDeclarations . . . . . . . . . . . . . . . . . . . . . . . 206

6.1.3 SeparateCompilation . . . . . . . . . . . . . . . . . . . . . . . 207

6.2 ArgumentPassing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

6.2.1 PassingArgumentsbyValue . . . . . . . . . . . . . . . . . . . 209

6.2.2 PassingArgumentsbyReference . . . . . . . . . . . . . . . . . 210

6.2.3 constParametersandArguments . . . . . . . . . . . . . . . . 212

6.2.4 ArrayParameters . . . . . . . . . . . . . . . . . . . . . . . . . . 214

x Contents

6.2.5 main:HandlingCommand-LineOptions . . . . . . . . . . . . 218

6.2.6 FunctionswithVaryingParameters . . . . . . . . . . . . . . . 220

6.3 Return Types and the returnStatement . . . . . . . . . . . . . . . . 222

6.3.1 FunctionswithNoReturnValue . . . . . . . . . . . . . . . . . 223

6.3.2 FunctionsThatReturnaValue . . . . . . . . . . . . . . . . . . 223

6.3.3 ReturningaPointer toanArray . . . . . . . . . . . . . . . . . 228

6.4 OverloadedFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

6.4.1 OverloadingandScope . . . . . . . . . . . . . . . . . . . . . . 234

6.5 Features forSpecializedUses . . . . . . . . . . . . . . . . . . . . . . . 236

6.5.1 DefaultArguments . . . . . . . . . . . . . . . . . . . . . . . . . 236

6.5.2 Inline and constexprFunctions . . . . . . . . . . . . . . . . 238

6.5.3 Aids for Debugging . . . . . . . . . . . . . . . . . . . . . . . . 240

6.6 FunctionMatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242

6.6.1 ArgumentTypeConversions . . . . . . . . . . . . . . . . . . . 245

6.7 Pointers toFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251

Chapter 7 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

7.1 DefiningAbstractDataTypes . . . . . . . . . . . . . . . . . . . . . . . 254

7.1.1 Designing the Sales_dataClass . . . . . . . . . . . . . . . . 254

7.1.2 Defining the Revised Sales_dataClass . . . . . . . . . . . . 256

7.1.3 DefiningNonmemberClass-RelatedFunctions . . . . . . . . . 260

7.1.4 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

7.1.5 Copy,Assignment, andDestruction . . . . . . . . . . . . . . . 267

7.2 AccessControl andEncapsulation . . . . . . . . . . . . . . . . . . . . 268

7.2.1 Friends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

7.3 AdditionalClassFeatures . . . . . . . . . . . . . . . . . . . . . . . . . 271

7.3.1 ClassMembersRevisited . . . . . . . . . . . . . . . . . . . . . 271

7.3.2 Functions That Return *this . . . . . . . . . . . . . . . . . . . 275

7.3.3 ClassTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277

7.3.4 FriendshipRevisited . . . . . . . . . . . . . . . . . . . . . . . . 279

7.4 ClassScope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

7.4.1 NameLookupandClassScope . . . . . . . . . . . . . . . . . . 283

7.5 ConstructorsRevisited . . . . . . . . . . . . . . . . . . . . . . . . . . . 288

7.5.1 Constructor InitializerList . . . . . . . . . . . . . . . . . . . . . 288

7.5.2 DelegatingConstructors . . . . . . . . . . . . . . . . . . . . . . 291

7.5.3 TheRoleof theDefaultConstructor . . . . . . . . . . . . . . . 293

7.5.4 ImplicitClass-TypeConversions . . . . . . . . . . . . . . . . . 294

7.5.5 AggregateClasses . . . . . . . . . . . . . . . . . . . . . . . . . 298

7.5.6 LiteralClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

7.6 staticClassMembers . . . . . . . . . . . . . . . . . . . . . . . . . . 300

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

Contents xi

Part II The C++ Library 307

Chapter 8 The IO Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

8.1 The IOClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

8.1.1 NoCopyorAssignfor IOObjects . . . . . . . . . . . . . . . . 311

8.1.2 ConditionStates . . . . . . . . . . . . . . . . . . . . . . . . . . 312

8.1.3 ManagingtheOutputBuffer . . . . . . . . . . . . . . . . . . . 314

8.2 File Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . 316

8.2.1 Using File Stream Objects . . . . . . . . . . . . . . . . . . . . . 317

8.2.2 File Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

8.3 stringStreams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

8.3.1 Using an istringstream . . . . . . . . . . . . . . . . . . . . 321

8.3.2 Using ostringstreams . . . . . . . . . . . . . . . . . . . . . 323

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324

Chapter 9 Sequential Containers . . . . . . . . . . . . . . . . . . . . . . . 325

9.1 Overviewof the SequentialContainers . . . . . . . . . . . . . . . . . . 326

9.2 ContainerLibraryOverview . . . . . . . . . . . . . . . . . . . . . . . . 328

9.2.1 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331

9.2.2 ContainerTypeMembers . . . . . . . . . . . . . . . . . . . . . 332

9.2.3 begin and endMembers . . . . . . . . . . . . . . . . . . . . . 333

9.2.4 DefiningandInitializingaContainer . . . . . . . . . . . . . . 334

9.2.5 Assignment and swap . . . . . . . . . . . . . . . . . . . . . . . 337

9.2.6 ContainerSizeOperations . . . . . . . . . . . . . . . . . . . . . 340

9.2.7 RelationalOperators . . . . . . . . . . . . . . . . . . . . . . . . 340

9.3 SequentialContainerOperations . . . . . . . . . . . . . . . . . . . . . 341

9.3.1 AddingElements toaSequentialContainer . . . . . . . . . . . 341

9.3.2 AccessingElements . . . . . . . . . . . . . . . . . . . . . . . . . 346

9.3.3 ErasingElements . . . . . . . . . . . . . . . . . . . . . . . . . . 348

9.3.4 Specialized forward_listOperations . . . . . . . . . . . . . 350

9.3.5 ResizingaContainer . . . . . . . . . . . . . . . . . . . . . . . . 352

9.3.6 ContainerOperationsMayInvalidateIterators . . . . . . . . . 353

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

9.5 Additional stringOperations . . . . . . . . . . . . . . . . . . . . . . 360

9.5.1 Other Ways to Construct strings . . . . . . . . . . . . . . . . 360

9.5.2 Other Ways to Change a string . . . . . . . . . . . . . . . . . 361

9.5.3 stringSearchOperations . . . . . . . . . . . . . . . . . . . . 364

9.5.4 The compareFunctions . . . . . . . . . . . . . . . . . . . . . . 366

9.5.5 NumericConversions . . . . . . . . . . . . . . . . . . . . . . . 367

9.6 ContainerAdaptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372

xii Contents

Chapter 10 Generic Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . 375

10.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376

10.2 AFirstLookat theAlgorithms . . . . . . . . . . . . . . . . . . . . . . 378

10.2.1 Read-OnlyAlgorithms . . . . . . . . . . . . . . . . . . . . . . . 379

10.2.2 AlgorithmsThatWriteContainerElements . . . . . . . . . . . 380

10.2.3 AlgorithmsThatReorderContainerElements . . . . . . . . . 383

10.3 CustomizingOperations . . . . . . . . . . . . . . . . . . . . . . . . . . 385

10.3.1 PassingaFunctiontoanAlgorithm . . . . . . . . . . . . . . . 386

10.3.2 LambdaExpressions . . . . . . . . . . . . . . . . . . . . . . . . 387

10.3.3 LambdaCapturesandReturns . . . . . . . . . . . . . . . . . . 392

10.3.4 BindingArguments . . . . . . . . . . . . . . . . . . . . . . . . 397

10.4 Revisiting Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401

10.4.1 Insert Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 401

10.4.2 iostream Iterators . . . . . . . . . . . . . . . . . . . . . . . . 403

10.4.3 Reverse Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . 407

10.5 StructureofGenericAlgorithms . . . . . . . . . . . . . . . . . . . . . 410

10.5.1 TheFive IteratorCategories . . . . . . . . . . . . . . . . . . . . 410

10.5.2 AlgorithmParameterPatterns . . . . . . . . . . . . . . . . . . 412

10.5.3 AlgorithmNamingConventions . . . . . . . . . . . . . . . . . 413

10.6 Container-SpecificAlgorithms . . . . . . . . . . . . . . . . . . . . . . . 415

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

Chapter 11 Associative Containers . . . . . . . . . . . . . . . . . . . . . . . 419

11.1 UsinganAssociativeContainer . . . . . . . . . . . . . . . . . . . . . . 420

11.2 Overviewof theAssociativeContainers . . . . . . . . . . . . . . . . . 423

11.2.1 DefininganAssociativeContainer . . . . . . . . . . . . . . . . 423

11.2.2 Requirements onKeyType . . . . . . . . . . . . . . . . . . . . 424

11.2.3 The pairType . . . . . . . . . . . . . . . . . . . . . . . . . . . 426

11.3 Operations onAssociativeContainers . . . . . . . . . . . . . . . . . . 428

11.3.1 AssociativeContainer Iterators . . . . . . . . . . . . . . . . . . 429

11.3.2 AddingElements . . . . . . . . . . . . . . . . . . . . . . . . . . 431

11.3.3 ErasingElements . . . . . . . . . . . . . . . . . . . . . . . . . . 434

11.3.4 Subscripting a map . . . . . . . . . . . . . . . . . . . . . . . . . 435

11.3.5 AccessingElements . . . . . . . . . . . . . . . . . . . . . . . . . 436

11.3.6 AWordTransformationMap . . . . . . . . . . . . . . . . . . . 440

11.4 TheUnorderedContainers . . . . . . . . . . . . . . . . . . . . . . . . . 443

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447

Chapter 12 DynamicMemory . . . . . . . . . . . . . . . . . . . . . . . . . . 449

12.1 DynamicMemoryandSmartPointers . . . . . . . . . . . . . . . . . . 450

12.1.1 The shared_ptrClass . . . . . . . . . . . . . . . . . . . . . . 450

12.1.2 ManagingMemoryDirectly . . . . . . . . . . . . . . . . . . . . 458

12.1.3 Using shared_ptrs with new . . . . . . . . . . . . . . . . . . 464

12.1.4 SmartPointers andExceptions . . . . . . . . . . . . . . . . . . 467

12.1.5 unique_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470

Contents xiii

12.1.6 weak_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473

12.2 DynamicArrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476

12.2.1 newandArrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 477

12.2.2 The allocatorClass . . . . . . . . . . . . . . . . . . . . . . . 481

12.3 UsingtheLibrary:AText-QueryProgram . . . . . . . . . . . . . . . . 484

12.3.1 Designof theQueryProgram . . . . . . . . . . . . . . . . . . . 485

12.3.2 DefiningtheQueryProgramClasses . . . . . . . . . . . . . . . 487

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491

Part III Tools for Class Authors 493

Chapter 13 Copy Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495

13.1 Copy,Assign, andDestroy . . . . . . . . . . . . . . . . . . . . . . . . . 496

13.1.1 TheCopyConstructor . . . . . . . . . . . . . . . . . . . . . . . 496

13.1.2 TheCopy-AssignmentOperator . . . . . . . . . . . . . . . . . 500

13.1.3 TheDestructor . . . . . . . . . . . . . . . . . . . . . . . . . . . 501

13.1.4 TheRuleofThree/Five . . . . . . . . . . . . . . . . . . . . . . 503

13.1.5 Using = default . . . . . . . . . . . . . . . . . . . . . . . . . . 506

13.1.6 PreventingCopies . . . . . . . . . . . . . . . . . . . . . . . . . 507

13.2 CopyControl andResourceManagement . . . . . . . . . . . . . . . . 510

13.2.1 ClassesThatActLikeValues . . . . . . . . . . . . . . . . . . . 511

13.2.2 DefiningClassesThatActLikePointers . . . . . . . . . . . . . 513

13.3 Swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516

13.4 ACopy-ControlExample . . . . . . . . . . . . . . . . . . . . . . . . . 519

13.5 ClassesThatManageDynamicMemory . . . . . . . . . . . . . . . . . 524

13.6 MovingObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531

13.6.1 RvalueReferences . . . . . . . . . . . . . . . . . . . . . . . . . 532

13.6.2 MoveConstructor andMoveAssignment . . . . . . . . . . . . 534

13.6.3 RvalueReferencesandMemberFunctions . . . . . . . . . . . 544

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549

Chapter 14 Overloaded Operations and Conversions . . . . . . . . . . . . . 551

14.1 BasicConcepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552

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

14.2.1 Overloading the Output Operator <<. . . . . . . . . . . . . . 557

14.2.2 Overloading the Input Operator >>. . . . . . . . . . . . . . . 558

14.3 Arithmetic andRelationalOperators . . . . . . . . . . . . . . . . . . . 560

14.3.1 EqualityOperators . . . . . . . . . . . . . . . . . . . . . . . . . 561

14.3.2 RelationalOperators . . . . . . . . . . . . . . . . . . . . . . . . 562

14.4 AssignmentOperators . . . . . . . . . . . . . . . . . . . . . . . . . . . 563

14.5 SubscriptOperator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564

14.6 Increment andDecrementOperators . . . . . . . . . . . . . . . . . . . 566

14.7 MemberAccessOperators . . . . . . . . . . . . . . . . . . . . . . . . . 569

14.8 Function-CallOperator . . . . . . . . . . . . . . . . . . . . . . . . . . . 571

xiv Contents

14.8.1 LambdasAreFunctionObjects . . . . . . . . . . . . . . . . . . 572

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

14.8.3 Callable Objects and function . . . . . . . . . . . . . . . . . 576

14.9 Overloading,Conversions, andOperators . . . . . . . . . . . . . . . . 579

14.9.1 ConversionOperators . . . . . . . . . . . . . . . . . . . . . . . 580

14.9.2 AvoidingAmbiguousConversions . . . . . . . . . . . . . . . . 583

14.9.3 FunctionMatchingandOverloadedOperators . . . . . . . . . 587

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590

Chapter 15 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . 591

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

15.2 DefiningBaseandDerivedClasses . . . . . . . . . . . . . . . . . . . . 594

15.2.1 DefiningaBaseClass . . . . . . . . . . . . . . . . . . . . . . . . 594

15.2.2 DefiningaDerivedClass . . . . . . . . . . . . . . . . . . . . . 596

15.2.3 Conversions andInheritance . . . . . . . . . . . . . . . . . . . 601

15.3 VirtualFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603

15.4 AbstractBaseClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608

15.5 AccessControl andInheritance . . . . . . . . . . . . . . . . . . . . . . 611

15.6 ClassScopeunder Inheritance . . . . . . . . . . . . . . . . . . . . . . . 617

15.7 Constructors andCopyControl . . . . . . . . . . . . . . . . . . . . . . 622

15.7.1 VirtualDestructors . . . . . . . . . . . . . . . . . . . . . . . . . 622

15.7.2 SynthesizedCopyControl andInheritance . . . . . . . . . . . 623

15.7.3 Derived-ClassCopy-ControlMembers . . . . . . . . . . . . . 625

15.7.4 InheritedConstructors . . . . . . . . . . . . . . . . . . . . . . . 628

15.8 Containers andInheritance . . . . . . . . . . . . . . . . . . . . . . . . 630

15.8.1 Writing a BasketClass . . . . . . . . . . . . . . . . . . . . . . 631

15.9 TextQueriesRevisited . . . . . . . . . . . . . . . . . . . . . . . . . . . 634

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

15.9.2 The Query_base and QueryClasses . . . . . . . . . . . . . . 639

15.9.3 TheDerivedClasses . . . . . . . . . . . . . . . . . . . . . . . . 642

15.9.4 The evalFunctions . . . . . . . . . . . . . . . . . . . . . . . . 645

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649

Chapter 16 Templates and Generic Programming . . . . . . . . . . . . . . . 651

16.1 DefiningaTemplate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652

16.1.1 FunctionTemplates . . . . . . . . . . . . . . . . . . . . . . . . . 652

16.1.2 ClassTemplates . . . . . . . . . . . . . . . . . . . . . . . . . . . 658

16.1.3 TemplateParameters . . . . . . . . . . . . . . . . . . . . . . . . 668

16.1.4 MemberTemplates . . . . . . . . . . . . . . . . . . . . . . . . . 672

16.1.5 Controlling Instantiations . . . . . . . . . . . . . . . . . . . . . 675

16.1.6 Efficiency and Flexibility . . . . . . . . . . . . . . . . . . . . . . 676

16.2 TemplateArgumentDeduction . . . . . . . . . . . . . . . . . . . . . . 678

16.2.1 Conversions andTemplateTypeParameters . . . . . . . . . . 679

16.2.2 Function-TemplateExplicitArguments . . . . . . . . . . . . . 681

16.2.3 Trailing Return Types and Type Transformation . . . . . . . . 683

Contents xv

16.2.4 FunctionPointers andArgumentDeduction . . . . . . . . . . 686

16.2.5 TemplateArgumentDeductionandReferences . . . . . . . . 687

16.2.6 Understanding std::move . . . . . . . . . . . . . . . . . . . . 690

16.2.7 Forwarding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692

16.3 OverloadingandTemplates . . . . . . . . . . . . . . . . . . . . . . . . 694

16.4 VariadicTemplates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699

16.4.1 WritingaVariadicFunctionTemplate . . . . . . . . . . . . . . 701

16.4.2 PackExpansion . . . . . . . . . . . . . . . . . . . . . . . . . . . 702

16.4.3 ForwardingParameterPacks . . . . . . . . . . . . . . . . . . . 704

16.5 Template Specializations . . . . . . . . . . . . . . . . . . . . . . . . . . 706

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713

Part IV Advanced Topics 715

Chapter 17 Specialized Library Facilities . . . . . . . . . . . . . . . . . . . 717

17.1 The tupleType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718

17.1.1 Defining and Initializing tuples . . . . . . . . . . . . . . . . . 718

17.1.2 Using a tuple toReturnMultipleValues . . . . . . . . . . . . 721

17.2 The bitsetType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723

17.2.1 Defining and Initializing bitsets . . . . . . . . . . . . . . . . 723

17.2.2 Operations on bitsets . . . . . . . . . . . . . . . . . . . . . . 725

17.3 RegularExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728

17.3.1 UsingtheRegularExpressionLibrary . . . . . . . . . . . . . . 729

17.3.2 TheMatchandRegex IteratorTypes . . . . . . . . . . . . . . . 734

17.3.3 UsingSubexpressions . . . . . . . . . . . . . . . . . . . . . . . 738

17.3.4 Using regex_replace . . . . . . . . . . . . . . . . . . . . . . 741

17.4 RandomNumbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745

17.4.1 Random-NumberEngines andDistribution . . . . . . . . . . . 745

17.4.2 OtherKinds ofDistributions . . . . . . . . . . . . . . . . . . . 749

17.5 The IOLibraryRevisited . . . . . . . . . . . . . . . . . . . . . . . . . . 752

17.5.1 FormattedInput andOutput . . . . . . . . . . . . . . . . . . . 753

17.5.2 UnformattedInput/OutputOperations . . . . . . . . . . . . . 761

17.5.3 RandomAccess toaStream . . . . . . . . . . . . . . . . . . . . 763

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769

Chapter 18 Tools for Large Programs . . . . . . . . . . . . . . . . . . . . . . 771

18.1 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772

18.1.1 ThrowinganException . . . . . . . . . . . . . . . . . . . . . . 772

18.1.2 CatchinganException . . . . . . . . . . . . . . . . . . . . . . . 775

18.1.3 Function tryBlocks andConstructors . . . . . . . . . . . . . 777

18.1.4 The noexceptExceptionSpecification . . . . . . . . . . . . . 779

18.1.5 ExceptionClassHierarchies . . . . . . . . . . . . . . . . . . . . 782

18.2 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785

18.2.1 NamespaceDefinitions . . . . . . . . . . . . . . . . . . . . . . 785

xvi Contents

18.2.2 UsingNamespaceMembers . . . . . . . . . . . . . . . . . . . . 792

18.2.3 Classes,Namespaces,andScope . . . . . . . . . . . . . . . . . 796

18.2.4 OverloadingandNamespaces . . . . . . . . . . . . . . . . . . 800

18.3 Multiple andVirtual Inheritance . . . . . . . . . . . . . . . . . . . . . 802

18.3.1 Multiple Inheritance . . . . . . . . . . . . . . . . . . . . . . . . 803

18.3.2 Conversions andMultipleBaseClasses . . . . . . . . . . . . . 805

18.3.3 ClassScopeunderMultiple Inheritance . . . . . . . . . . . . . 807

18.3.4 Virtual Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . 810

18.3.5 Constructors andVirtual Inheritance . . . . . . . . . . . . . . . 813

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816

Chapter 19 Specialized Tools and Techniques . . . . . . . . . . . . . . . . . 819

19.1 Controlling Memory Allocation . . . . . . . . . . . . . . . . . . . . . . 820

19.1.1 Overloading new and delete . . . . . . . . . . . . . . . . . . 820

19.1.2 Placement newExpressions . . . . . . . . . . . . . . . . . . . . 823

19.2 Run-TimeTypeIdentification . . . . . . . . . . . . . . . . . . . . . . . 825

19.2.1 The dynamic_castOperator . . . . . . . . . . . . . . . . . . 825

19.2.2 The typeidOperator . . . . . . . . . . . . . . . . . . . . . . . 826

19.2.3 UsingRTTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828

19.2.4 The type_infoClass . . . . . . . . . . . . . . . . . . . . . . . 831

19.3 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832

19.4 Pointer toClassMember . . . . . . . . . . . . . . . . . . . . . . . . . . 835

19.4.1 Pointers toDataMembers . . . . . . . . . . . . . . . . . . . . . 836

19.4.2 Pointers toMemberFunctions . . . . . . . . . . . . . . . . . . 838

19.4.3 UsingMemberFunctions asCallableObjects . . . . . . . . . . 841

19.5 NestedClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843

19.6 union:ASpace-SavingClass . . . . . . . . . . . . . . . . . . . . . . . 847

19.7 LocalClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 852

19.8 InherentlyNonportableFeatures . . . . . . . . . . . . . . . . . . . . . 854

19.8.1 Bit-fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854

19.8.2 volatileQualifier . . . . . . . . . . . . . . . . . . . . . . . . 856

19.8.3 Linkage Directives: extern "C" . . . . . . . . . . . . . . . . . 857

ChapterSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 862

DefinedTerms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 862

Appendix A The Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865

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

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

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

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

A.2.3 BinarySearchAlgorithms . . . . . . . . . . . . . . . . . . . . . 873

A.2.4 AlgorithmsThatWriteContainerElements . . . . . . . . . . . 873

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

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

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

A.2.8 SetAlgorithms forSortedSequences . . . . . . . . . . . . . . . 880

Contents xvii

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

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

A.3 RandomNumbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882

A.3.1 RandomNumberDistributions . . . . . . . . . . . . . . . . . . 883

A.3.2 RandomNumberEngines . . . . . . . . . . . . . . . . . . . . . 884

Index

New Features in C++11

2.1.1 long longType . . . . . . . . . . . . . . . . . . . . . . . . . . 33

2.2.1 List Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . 43

2.3.2 nullptrLiteral . . . . . . . . . . . . . . . . . . . . . . . . . . 54

2.4.4 constexprVariables . . . . . . . . . . . . . . . . . . . . . . . 66

2.5.1 TypeAliasDeclarations . . . . . . . . . . . . . . . . . . . . . . 68

2.5.2 The autoTypeSpecifier . . . . . . . . . . . . . . . . . . . . . . 68

2.5.3 The decltypeTypeSpecifier . . . . . . . . . . . . . . . . . . . 70

2.6.1 In-Class Initializers . . . . . . . . . . . . . . . . . . . . . . . . . 73

3.2.2 Using auto or decltype forTypeAbbreviation . . . . . . . 88

3.2.3 Range forStatement . . . . . . . . . . . . . . . . . . . . . . . 91

3.3 Defining a vector of vectors . . . . . . . . . . . . . . . . . . 97

3.3.1 List Initialization for vectors . . . . . . . . . . . . . . . . . . 98

3.4.1 Container cbegin and cendFunctions . . . . . . . . . . . . . 109

3.5.3 Library begin and endFunctions . . . . . . . . . . . . . . . . 118

3.6 Using auto or decltype to SimplifyDeclarations . . . . . . 129

4.2 RoundingRules forDivision . . . . . . . . . . . . . . . . . . . 141

4.4 Assignment fromaBracedListofValues . . . . . . . . . . . . 145

4.9 sizeofAppliedtoaClassMember . . . . . . . . . . . . . . . 157

5.4.3 Range forStatement . . . . . . . . . . . . . . . . . . . . . . . 187

6.2.6 Library initializer_listClass . . . . . . . . . . . . . . . 220

6.3.2 List InitializingaReturnValue . . . . . . . . . . . . . . . . . . 226

6.3.3 Declaring a Trailing Return Type . . . . . . . . . . . . . . . . . 229

6.3.3 Using decltype to Simplify Return Type Declarations . . . . 230

6.5.2 constexprFunctions . . . . . . . . . . . . . . . . . . . . . . . 239

7.1.4 Using = default toGenerateaDefaultConstructor . . . . . 265

7.3.1 In-class Initializers forMembersofClassType . . . . . . . . . 274

7.5.2 DelegatingConstructors . . . . . . . . . . . . . . . . . . . . . . 291

7.5.6 constexprConstructors . . . . . . . . . . . . . . . . . . . . . 299

8.2.1 Using strings for File Names . . . . . . . . . . . . . . . . . . 317

9.1 The array and forward_listContainers . . . . . . . . . . 327

9.2.3 Container cbegin and cendFunctions . . . . . . . . . . . . . 334

9.2.4 List InitializationforContainers . . . . . . . . . . . . . . . . . 336

9.2.5 Container Nonmember swapFunctions . . . . . . . . . . . . . 339

9.3.1 Return Type for Container insertMembers . . . . . . . . . . 344

9.3.1 Container emplaceMembers . . . . . . . . . . . . . . . . . . 345

xix

xx New Features in C++11

9.4 shrink_to_fit . . . . . . . . . . . . . . . . . . . . . . . . . . 357

9.5.5 Numeric Conversion Functions for strings . . . . . . . . . . 367

10.3.2 LambdaExpressions . . . . . . . . . . . . . . . . . . . . . . . . 388

10.3.3 Trailing Return Type in Lambda Expressions . . . . . . . . . . 396

10.3.4 The Library bindFunction . . . . . . . . . . . . . . . . . . . . 397

11.2.1 List Initializationof anAssociativeContainer . . . . . . . . . . 423

11.2.3 List Initializing pairReturnType . . . . . . . . . . . . . . . . 427

11.3.2 List Initialization of a pair . . . . . . . . . . . . . . . . . . . . 431

11.4 TheUnorderedContainers . . . . . . . . . . . . . . . . . . . . 443

12.1 SmartPointers . . . . . . . . . . . . . . . . . . . . . . . . . . . 450

12.1.1 The shared_ptrClass . . . . . . . . . . . . . . . . . . . . . . 450

12.1.2 List InitializationofDynamicallyAllocatedObjects . . . . . . 459

12.1.2 autoandDynamicAllocation . . . . . . . . . . . . . . . . . . 459

12.1.5 The unique_ptrClass . . . . . . . . . . . . . . . . . . . . . . 470

12.1.6 The weak_ptrClass . . . . . . . . . . . . . . . . . . . . . . . . 473

12.2.1 Range for Doesn’t Apply to Dynamically Allocated Arrays . 477

12.2.1 List InitializationofDynamicallyAllocatedArrays . . . . . . 478

12.2.1 autoCan’tBeUsedtoAllocateanArray . . . . . . . . . . . . 478

12.2.2 allocator::constructCanUseanyConstructor . . . . . 482

13.1.5 Using = default forCopy-ControlMembers . . . . . . . . . 506

13.1.6 Using = delete toPreventCopyingClassObjects . . . . . . 507

13.5 MovingInsteadofCopyingClassObjects . . . . . . . . . . . . 529

13.6.1 RvalueReferences . . . . . . . . . . . . . . . . . . . . . . . . . 532

13.6.1 The Library moveFunction . . . . . . . . . . . . . . . . . . . . 533

13.6.2 MoveConstructor andMoveAssignment . . . . . . . . . . . . 534

13.6.2 Move Constructors Usually Should Be noexcept . . . . . . . 535

13.6.2 MoveIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 543

13.6.3 ReferenceQualifiedMemberFunctions . . . . . . . . . . . . . 546

14.8.3 The functionClassTemplate . . . . . . . . . . . . . . . . . . 577

14.9.1 explicitConversionOperators . . . . . . . . . . . . . . . . 582

15.2.2 overrideSpecifier forVirtualFunctions . . . . . . . . . . . . 596

15.2.2 Preventing Inheritance by Defining a Class as final . . . . . 600

15.3 override and final Specifiers for Virtual Functions . . . . 606

15.7.2 DeletedCopyControl andInheritance . . . . . . . . . . . . . . 624

15.7.4 InheritedConstructors . . . . . . . . . . . . . . . . . . . . . . . 628

16.1.2 DeclaringaTemplateTypeParameteras aFriend . . . . . . . 666

16.1.2 TemplateTypeAliases . . . . . . . . . . . . . . . . . . . . . . . 666

16.1.3 DefaultTemplateArguments forTemplateFunctions . . . . . 670

16.1.5 ExplicitControlof Instantiation. . . . . . . . . . . . . . . . . . 675

16.2.3 Template Functions and Trailing Return Types . . . . . . . . . 684

16.2.5 ReferenceCollapsingRules . . . . . . . . . . . . . . . . . . . . 688

16.2.6 static_cast fromanLvaluetoanRvalue . . . . . . . . . . 691

16.2.7 The Library forwardFunction . . . . . . . . . . . . . . . . . . 694

16.4 VariadicTemplates . . . . . . . . . . . . . . . . . . . . . . . . . 699

16.4 The sizeof…Operator . . . . . . . . . . . . . . . . . . . . . 700

16.4.3 VariadicTemplates andForwarding . . . . . . . . . . . . . . . 704

New Features in C++11 xxi

17.1 The Library TupleClassTemplate . . . . . . . . . . . . . . . . 718

17.2.2 New bitsetOperations . . . . . . . . . . . . . . . . . . . . . 726

17.3 TheRegularExpressionLibrary . . . . . . . . . . . . . . . . . 728

17.4 TheRandomNumberLibrary . . . . . . . . . . . . . . . . . . 745

17.5.1 Floating-Point FormatControl . . . . . . . . . . . . . . . . . . 757

18.1.4 The noexceptExceptionSpecifier . . . . . . . . . . . . . . . . 779

18.1.4 The noexceptOperator . . . . . . . . . . . . . . . . . . . . . 780

18.2.1 InlineNamespaces . . . . . . . . . . . . . . . . . . . . . . . . . 790

18.3.1 InheritedConstructors andMultiple Inheritance . . . . . . . . 804

19.3 Scoped enums . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832

19.3 Specifying the Type Used to Hold an enum . . . . . . . . . . . 834

19.3 Forward Declarations for enums . . . . . . . . . . . . . . . . . 834

19.4.3 The Library mem_fnClassTemplate . . . . . . . . . . . . . . . 843

19.6 UnionMembersofClassTypes . . . . . . . . . . . . . . . . . . 848

"C++ Primer 英文版(第 5 版)"试读
······

  • C++ Primer英文版(第5版)英文版
  • 《C++Primer (第5版)》中英文试读版

评论 ······

有点厚

终于在C++14推出之后读过介绍C++11的第五版了

大概看五六遍了吧。之后工作要实打实用C/C++,回家又刷一遍,意外发现还有静心功效。

英文原本,彩页印刷,书籍经典。

点击星号评分!

平均分 0 / 5. 投票数: 0

还没有投票!请为他投一票。

评论 抢沙发

评论前必须登录!

 

登录

找回密码

注册