C++ Primer 第4版評註版

ters ters strain

內容介紹

《C++ Primer》是一本系統而絕佳的C++ 教材,它全面而深入地講解了C++ 語言及其標準庫。本書作者Stanley B. Lippman 在20 世紀80 年代早期即在C++ 之父Bjarne Stroustrup 領導下開發C++ 編譯器,另一作者Josée Lajoie 曾多年擔任C++ 標準委員會核心語言組主席,他們對這門程式語言的理解與把握非常人可比。本書對C++ 語法和語 義的闡釋兼具準確性與可讀性,在坊間無出其右者。第4 版更吸收了先進的C++ 教學經驗,在內容組織上對初學者更加友好,詳略得當且重點突出,使讀者能更快上手編寫有用的程式,也更適合自學。全球已有45 萬人通過該 書的各個版本學習了C++ 編程。
對於國外技術圖書,選擇翻譯版還是影印版,常常讓人陷入兩難的境地。本評註版力邀國內資深專家執筆,在英文原著基礎上增加中文點評與注釋,旨在融合二者之長,既保留經典的原創文字與味道,又以先行者的學研心得與實踐感悟,對讀者閱讀與學習加以點撥、指明捷徑。經過評註的版本,更值得反覆閱讀與體會。希望這本書能夠幫助您跨越C++ 的重重險阻,領略高處才有的壯美風光,做一個成功而快樂的C++ 程式設計師。

作者介紹

陳碩,北京師範大學碩士,擅長 C++ 多執行緒網路編程和實時分散式系統架構。現任職於香港某跨國金融公司 IT 部門,從事實時外匯交易系統開發。編寫了開源 C++ 網路庫muduo;參與翻譯了《代碼大全(第二版)》和《C++ 編程規範(繁體版)》;2009 年在上海 C++ 技術大會做技術演講《當析構函式遇到多執行緒》,同時擔任 Stanley Lippman 先生的口譯員;2010 年在珠三角技術沙龍做技術演講《分散式系統的工程化開發方法》;2012年在“我們的開源項目”深圳站做《Muduo網路庫:現代非阻塞C++網路編程》演講。

作品目錄

Preface
Chapter 1 Getting Started
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
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
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
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
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
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
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
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
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
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 multisetTypes5
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
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
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
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
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
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
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
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 731
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
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

熱門詞條

聯絡我們