Professional C++ (4th Edition)

This book is the advanced manual for C++ programming. Designed to help experienced developers get more out of the latest release, this book skims over the basics and dives right in to exploiting the full capabilities of C++17. Each feature is explained by example, each including actual code snippets...

Celý popis

Uloženo v:
Podrobná bibliografie
Hlavní autor: Gregoire, Marc
Médium: E-kniha Kniha
Jazyk:angličtina
Vydáno: Newark John Wiley & Sons 2018
Wrox
John Wiley & Sons, Incorporated
Vydání:4
Témata:
ISBN:1119421306, 9781119421306, 9781119695400, 1119695406
On-line přístup:Získat plný text
Tagy: Přidat tag
Žádné tagy, Buďte první, kdo vytvoří štítek k tomuto záznamu!
Obsah:
  • Title Page Introduction Table of Contents Part I. Introduction to Professional C++ 1. A Crash Course in C++ and the Standard Library 2. Working with Strings and String Views 3. Coding with Style Part II. Professional C++ Software Design 4. Designing Professional C++ Programs 5. Designing with Objects 6. Designing for Reuse Part III. C++ Coding the Professional Way 7. Memory Management 8. Gaining Proficiency with Classes and Objects 9. Mastering Classes and Objects 10. Discovering Inheritance Techniques 11. C++ Quirks, Oddities, and Incidentals 12. Writing Generic Code with Templates 13. Demystifying C++ I/O 14. Handling Errors 15. Overloading C++ Operators 16. Overview of the C++ Standard Library 17. Understanding Containers and Iterators 18. Mastering Standard Library Algorithms 19. String Localization and Regular Expressions 20. Additional Library Utilities Part IV. Mastering Advanced Features of C++ 21. Customizing and Extending the Standard Library 22. Advanced Templates 23. Multithreaded Programming with C++ Part V. C++ Software Engineering 24. Maximizing Software Engineering Methods 25. Writing Efficient C++ 26. Becoming Adept at Testing 27. Conquering Debugging 28. Incorporating Design Techniques and Frameworks 29. Applying Design Patterns 30. Developing Cross-Platform and Cross-Language Applications Appendices Index
  • 28 Incorporating Design Techniques and Frameworks -- "I CAN NEVER REMEMBER HOW TO…" -- THERE MUST BE A BETTER WAY -- OBJECT-ORIENTED FRAMEWORKS -- SUMMARY -- 29 Applying Design Patterns -- THE ITERATOR PATTERN -- THE SINGLETON PATTERN -- THE ABSTRACT FACTORY PATTERN -- THE PROXY PATTERN -- THE ADAPTOR PATTERN -- THE DECORATOR PATTERN -- THE CHAIN OF RESPONSIBILITY PATTERN -- THE OBSERVER PATTERN -- SUMMARY -- NOTE -- 30 Developing Cross-Platform and Cross-Language Applications -- CROSS-PLATFORM DEVELOPMENT -- CROSS-LANGUAGE DEVELOPMENT -- SUMMARY -- A: C++ Interviews -- CHAPTER 1: A CRASH COURSE IN C++ AND THE STANDARD LIBRARY -- CHAPTERS 2 AND 19: WORKING WITH STRINGS AND STRING VIEWS, STRING LOCALIZATION, AND REGULAR EXPRESSIONS -- CHAPTER 3: CODING WITH STYLE -- CHAPTER 4: DESIGNING PROFESSIONAL C++ PROGRAMS -- CHAPTER 5: DESIGNING WITH OBJECTS -- CHAPTER 6: DESIGNING FOR REUSE -- CHAPTER 7: MEMORY MANAGEMENT -- CHAPTERS 8 AND 9: GAINING PROFICIENCY WITH CLASSES AND OBJECTS, AND MASTERING CLASSES AND OBJECTS -- CHAPTER 10: DISCOVERING INHERITANCE TECHNIQUES -- CHAPTER 11: C++ QUIRKS, ODDITIES, AND INCIDENTALS -- CHAPTERS 12 AND 22: WRITING GENERIC CODE WITH TEMPLATES, AND ADVANCED TEMPLATES -- CHAPTER 13: DEMYSTIFYING C++ I/O -- CHAPTER 14: HANDLING ERRORS -- CHAPTER 15: OVERLOADING C++ OPERATORS -- CHAPTERS 16, 17, 18, AND 21: THE STANDARD LIBRARY -- CHAPTER 20: ADDITIONAL LIBRARY UTILITIES -- CHAPTER 23: MULTITHREADED PROGRAMMING WITH C++ -- CHAPTER 24: MAXIMIZING SOFTWARE ENGINEERING METHODS -- CHAPTER 25: WRITING EFFICIENT C++ -- CHAPTER 26: BECOMING ADEPT AT TESTING -- CHAPTER 27: CONQUERING DEBUGGING -- CHAPTER 28: INCORPORATING DESIGN TECHNIQUES AND FRAMEWORKS -- CHAPTER 29: APPLYING DESIGN PATTERNS -- CHAPTER 30: DEVELOPING CROSS-PLATFORM AND CROSS-LANGUAGE APPLICATIONS -- B: Annotated Bibliography -- C++ -- UNIFIED MODELING LANGUAGE
  • STD::FUNCTION -- LAMBDA EXPRESSIONS -- FUNCTION OBJECTS -- ALGORITHM DETAILS -- ALGORITHMS EXAMPLE: AUDITING VOTER REGISTRATIONS -- SUMMARY -- NOTE -- 19 String Localization and Regular Expressions -- LOCALIZATION -- REGULAR EXPRESSIONS -- SUMMARY -- 20 Additional Library Utilities -- RATIOS -- THE CHRONO LIBRARY -- RANDOM NUMBER GENERATION -- OPTIONAL -- VARIANT -- ANY -- TUPLES -- FILESYSTEM SUPPORT LIBRARY -- SUMMARY -- NOTE -- PART IV: Mastering Advanced Features of C++ -- 21 Customizing and Extending the Standard Library -- ALLOCATORS -- STREAM ITERATORS -- ITERATOR ADAPTORS -- EXTENDING THE STANDARD LIBRARY -- SUMMARY -- NOTE -- 22 Advanced Templates -- MORE ABOUT TEMPLATE PARAMETERS -- CLASS TEMPLATE PARTIAL SPECIALIZATION -- EMULATING FUNCTION PARTIAL SPECIALIZATION WITH OVERLOADING -- TEMPLATE RECURSION -- VARIADIC TEMPLATES -- METAPROGRAMMING -- SUMMARY -- 23 Multithreaded Programming with C++ -- INTRODUCTION -- THREADS -- ATOMIC OPERATIONS LIBRARY -- MUTUAL EXCLUSION -- CONDITION VARIABLES -- FUTURES -- EXAMPLE: MULTITHREADED LOGGER CLASS -- THREAD POOLS -- THREADING DESIGN AND BEST PRACTICES -- SUMMARY -- NOTES -- PART V: C++ Software Engineering -- 24 Maximizing Software Engineering Methods -- THE NEED FOR PROCESS -- SOFTWARE LIFE CYCLE MODELS -- SOFTWARE ENGINEERING METHODOLOGIES -- BUILDING YOUR OWN PROCESS AND METHODOLOGY -- SOURCE CODE CONTROL -- SUMMARY -- 25 Writing Efficient C++ -- OVERVIEW OF PERFORMANCE AND EFFICIENCY -- LANGUAGE-LEVEL EFFICIENCY -- DESIGN-LEVEL EFFICIENCY -- PROFILING -- SUMMARY -- 26 Becoming Adept at Testing -- QUALITY CONTROL -- UNIT TESTING -- HIGHER-LEVEL TESTING -- TIPS FOR SUCCESSFUL TESTING -- SUMMARY -- NOTES -- 27 Conquering Debugging -- THE FUNDAMENTAL LAW OF DEBUGGING -- BUG TAXONOMIES -- AVOIDING BUGS -- PLANNING FOR BUGS -- STATIC ASSERTIONS -- DEBUGGING TECHNIQUES -- SUMMARY -- NOTES
  • Intro -- TITLE PAGE -- TABLE OF CONTENTS -- INTRODUCTION -- WHO THIS BOOK IS FOR -- WHAT THIS BOOK COVERS -- HOW THIS BOOK IS STRUCTURED -- WHAT YOU NEED TO USE THIS BOOK -- CONVENTIONS -- SOURCE CODE -- ERRATA -- NOTES -- PART I: Introduction to Professional C++ -- 1 A Crash Course in C++ and the Standard Library -- THE BASICS OF C++ -- DIVING DEEPER INTO C++ -- C++ AS AN OBJECT-ORIENTED LANGUAGE -- UNIFORM INITIALIZATION -- THE STANDARD LIBRARY -- YOUR FIRST USEFUL C++ PROGRAM -- SUMMARY -- NOTE -- 2 Working with Strings and String Views -- DYNAMIC STRINGS -- SUMMARY -- 3 Coding with Style -- THE IMPORTANCE OF LOOKING GOOD -- DOCUMENTING YOUR CODE -- DECOMPOSITION -- NAMING -- USING LANGUAGE FEATURES WITH STYLE -- FORMATTING -- STYLISTIC CHALLENGES -- SUMMARY -- PART II: Professional C++ Software Design -- 4 Designing Professional C++ Programs -- WHAT IS PROGRAMMING DESIGN? -- THE IMPORTANCE OF PROGRAMMING DESIGN -- DESIGNING FOR C++ -- TWO RULES FOR C++ DESIGN -- REUSING EXISTING CODE -- DESIGNING A CHESS PROGRAM -- SUMMARY -- 5 Designing with Objects -- AM I THINKING PROCEDURALLY? -- THE OBJECT-ORIENTED PHILOSOPHY -- LIVING IN A WORLD OF OBJECTS -- OBJECT RELATIONSHIPS -- ABSTRACTION -- SUMMARY -- 6 Designing for Reuse -- THE REUSE PHILOSOPHY -- HOW TO DESIGN REUSABLE CODE -- SUMMARY -- PART III: C++ Coding the Professional Way -- 7 Memory Management -- WORKING WITH DYNAMIC MEMORY -- ARRAY-POINTER DUALITY -- LOW-LEVEL MEMORY OPERATIONS -- SMART POINTERS -- COMMON MEMORY PITFALLS -- SUMMARY -- NOTE -- 8 Gaining Proficiency with Classes and Objects -- INTRODUCING THE SPREADSHEET EXAMPLE -- WRITING CLASSES -- OBJECT LIFE CYCLES -- SUMMARY -- 9 Mastering Classes and Objects -- FRIENDS -- DYNAMIC MEMORY ALLOCATION IN OBJECTS -- MORE ABOUT METHODS -- DIFFERENT KINDS OF DATA MEMBERS -- NESTED CLASSES -- ENUMERATED TYPES INSIDE CLASSES
  • OPERATOR OVERLOADING -- BUILDING STABLE INTERFACES -- SUMMARY -- 10 Discovering Inheritance Techniques -- BUILDING CLASSES WITH INHERITANCE -- INHERITANCE FOR REUSE -- RESPECT YOUR PARENTS -- INHERITANCE FOR POLYMORPHISM -- MULTIPLE INHERITANCE -- INTERESTING AND OBSCURE INHERITANCE ISSUES -- SUMMARY -- 11 C++ Quirks, Oddities, and Incidentals -- REFERENCES -- KEYWORD CONFUSION -- TYPES AND CASTS -- SCOPE RESOLUTION -- ATTRIBUTES -- USER-DEFINED LITERALS -- HEADER FILES -- C UTILITIES -- SUMMARY -- NOTES -- 12 Writing Generic Code with Templates -- OVERVIEW OF TEMPLATES -- CLASS TEMPLATES -- FUNCTION TEMPLATES -- VARIABLE TEMPLATES -- SUMMARY -- 13 Demystifying C++ I/O -- USING STREAMS -- STRING STREAMS -- FILE STREAMS -- BIDIRECTIONAL I/O -- SUMMARY -- 14 Handling Errors -- ERRORS AND EXCEPTIONS -- EXCEPTION MECHANICS -- EXCEPTIONS AND POLYMORPHISM -- RETHROWING EXCEPTIONS -- STACK UNWINDING AND CLEANUP -- COMMON ERROR-HANDLING ISSUES -- PUTTING IT ALL TOGETHER -- SUMMARY -- NOTES -- 15 Overloading C++ Operators -- OVERVIEW OF OPERATOR OVERLOADING -- OVERLOADING THE ARITHMETIC OPERATORS -- OVERLOADING THE BITWISE AND BINARY LOGICAL OPERATORS -- OVERLOADING THE INSERTION AND EXTRACTION OPERATORS -- OVERLOADING THE SUBSCRIPTING OPERATOR -- OVERLOADING THE FUNCTION CALL OPERATOR -- OVERLOADING THE DEREFERENCING OPERATORS -- WRITING CONVERSION OPERATORS -- OVERLOADING THE MEMORY ALLOCATION AND DEALLOCATION OPERATORS -- SUMMARY -- NOTE -- 16 Overview of the C++ Standard Library -- CODING PRINCIPLES -- OVERVIEW OF THE C++ STANDARD LIBRARY -- SUMMARY -- NOTE -- 17 Understanding Containers and Iterators -- CONTAINERS OVERVIEW -- SEQUENTIAL CONTAINERS -- CONTAINER ADAPTORS -- ORDERED ASSOCIATIVE CONTAINERS -- UNORDERED ASSOCIATIVE CONTAINERS OR HASH TABLES -- OTHER CONTAINERS -- SUMMARY -- 18 Mastering Standard Library Algorithms -- OVERVIEW OF ALGORITHMS
  • ALGORITHMS AND DATA STRUCTURES -- RANDOM NUMBERS -- OPEN-SOURCE SOFTWARE -- SOFTWARE ENGINEERING METHODOLOGY -- PROGRAMMING STYLE -- COMPUTER ARCHITECTURE -- EFFICIENCY -- TESTING -- DEBUGGING -- DESIGN PATTERNS -- OPERATING SYSTEMS -- MULTITHREADED PROGRAMMING -- C: Standard Library Header Files -- THE C STANDARD LIBRARY -- CONTAINERS -- ALGORITHMS, ITERATORS, AND ALLOCATORS -- GENERAL UTILITIES -- MATHEMATICAL UTILITIES -- EXCEPTIONS -- I/O STREAMS -- THREADING SUPPORT LIBRARY -- D: Introduction to UML -- TYPES OF DIAGRAMS -- CLASS DIAGRAMS -- END USER LICENSE AGREEMENT
  • The Reuse Philosophy -- How to Design Reusable Code -- Use Abstraction -- Structure Your Code for Optimal Reuse -- Avoid Combining Unrelated or Logically Separate Concepts -- Use Templates for Generic Data Structures and Algorithms -- Provide Appropriate Checks and Safeguards -- Design for Extensibility -- Design Usable Interfaces -- Consider the Audience -- Consider the Purpose -- Design Interfaces That Are Easy to Use -- Design General-Purpose Interfaces -- Reconciling Generality and Ease of Use -- Designing a Successful Abstraction -- The SOLID Principles -- Summary -- Exercises -- Part III: C++ Coding the Professional Way -- Chapter 7: Memory Management -- Working with Dynamic Memory -- How to Picture Memory -- Allocation and Deallocation -- Using new and delete -- What About My Good Friend malloc? -- When Memory Allocation Fails -- Arrays -- Arrays of Primitive Types -- Arrays of Objects -- Deleting Arrays -- Multidimensional Arrays -- Working with Pointers -- A Mental Model for Pointers -- Casting with Pointers -- Array-Pointer Duality -- Arrays Are Pointers! -- Not All Pointers Are Arrays! -- Low-Level Memory operations -- Pointer Arithmetic -- Custom Memory Management -- Garbage Collection -- Object Pools -- Common Memory Pitfalls -- Underallocating Data Buffers and Out-of-Bounds Memory Access -- Memory Leaks -- Finding and Fixing Memory Leaks in Windows with Visual C++ -- Finding and Fixing Memory Leaks in Linux with Valgrind -- Double-Deletion and Invalid Pointers -- Smart Pointers -- unique_ptr -- Creating unique_ptrs -- Using unique_ptrs -- unique_ptr and C-Style Arrays -- Custom Deleters -- shared_ptr -- Creating and Using shared_ptrs -- The Need for Reference Counting -- Casting a shared_ptr -- Aliasing -- weak_ptr -- Passing to Functions -- Returning from Functions -- enable_shared_from_this -- The Old and Removed auto_ptr -- Summary
  • Exercises -- Chapter 8: Gaining Proficiency with Classes and Objects -- Introducing the Spreadsheet Example -- Writing Classes -- Class Definitions -- Class Members -- Access Control -- Order of Declarations -- In-Class Member Initializers -- Defining Methods -- Accessing Data Members -- Calling Other Methods -- The this Pointer -- Using Objects -- Objects on the Stack -- Objects on the Free Store -- Understanding Object Life Cycles -- Object Creation -- Writing Constructors -- Using Constructors -- Providing Multiple Constructors -- Default Constructors -- Constructor Initializers -- Copy Constructors -- Initializer-List Constructors -- Delegating Constructors -- Converting Constructors and Explicit Constructors -- Summary of Compiler-Generated Constructors -- Object Destruction -- Assigning to Objects -- Declaring an Assignment Operator -- Defining an Assignment Operator -- Explicitly Defaulted and Deleted Assignment Operator -- Compiler-Generated Copy Constructor and Copy Assignment Operator -- Distinguishing Copying from Assignment -- Objects as Return Values -- Copy Constructors and Object Members -- Summary -- Exercises -- Chapter 9: Mastering Classes and Objects -- Friends -- Dynamic Memory Allocation in Objects -- The Spreadsheet Class -- Freeing Memory with Destructors -- Handling Copying and Assignment -- The Spreadsheet Copy Constructor -- The Spreadsheet Assignment Operator -- Disallowing Assignment and Pass-by-Value -- Handling Moving with Move Semantics -- Rvalue References -- Implementing Move Semantics -- Testing the Spreadsheet Move Operations -- Implementing a Swap Function with Move Semantics -- Using std::move() in Return Statements -- Optimal Way to Pass Arguments to Functions -- Rule of Zero -- More About Methods -- static Methods -- const Methods -- mutable Data Members -- Method Overloading -- Overloading Based on const
  • Your First Bigger C++ Program -- An Employee Records System -- The Employee Class -- Employee.cppm -- Employee.cpp -- EmployeeTest.cpp -- The Database Class -- Database.cppm -- Database.cpp -- DatabaseTest.cpp -- The User Interface -- Evaluating the Program -- Summary -- Exercises -- Chapter 2: Working with Strings and String Views -- Dynamic Strings -- C-Style Strings -- String Literals -- Raw String Literals -- The C++ std::string Class -- What Is Wrong with C-Style Strings? -- Using the string Class -- std::string Literals -- CTAD with std::vector and Strings -- Numeric Conversions -- High-Level Numeric Conversions -- Low-Level Numeric Conversions -- The std::string_view Class -- std::string_view and Temporary Strings -- std::string_view Literals -- Nonstandard Strings -- String Formatting -- Format Specifiers -- width -- [fill]align -- sign -- # -- type -- precision -- 0 -- Format Specifier Errors -- Support for Custom Types -- Summary -- Exercises -- Chapter 3: Coding with Style -- The Importance of Looking Good -- Thinking Ahead -- Elements of Good Style -- Documenting Your Code -- Reasons to Write Comments -- Commenting to Explain Usage -- Commenting to Explain Complicated Code -- Commenting to Convey Meta-information -- Commenting Styles -- Commenting Every Line -- Prefix Comments -- Fixed-Format Comments -- Ad Hoc Comments -- Self-Documenting Code -- Decomposition -- Decomposition Through Refactoring -- Decomposition by Design -- Decomposition in This Book -- Naming -- Choosing a Good Name -- Naming Conventions -- Counters -- Prefixes -- Hungarian Notation -- Getters and Setters -- Capitalization -- Namespaced Constants -- Using Language Features with Style -- Use Constants -- Use References Instead of Pointers -- Use Custom Exceptions -- Formatting -- The Curly Brace Alignment Debate -- Coming to Blows over Spaces and Parentheses
  • Explicitly Deleting Overloads
  • Spaces, Tabs, and Line Breaks -- Stylistic Challenges -- Summary -- Exercises -- Part II: Professional C++ Software Design -- Chapter 4: Designing Professional C++ Programs -- What Is Programming Design? -- The Importance of Programming Design -- Designing for C++ -- Two Rules for Your Own C++ Designs -- Abstraction -- Benefiting from Abstraction -- Incorporating Abstraction in Your Design -- Reuse -- Writing Reusable Code -- Reusing Designs -- Reusing Existing Code -- A Note on Terminology -- Deciding Whether to Reuse Code or Write it Yourself -- Advantages to Reusing Code -- Disadvantages to Reusing Code -- Putting It Together to Make a Decision -- Guidelines for Choosing a Library to Reuse -- Understand the Capabilities and Limitations -- Understand the Learning Cost -- Understand the Performance -- Understand Platform Limitations -- Understand Licensing -- Understand Support and Know Where to Find Help -- Prototype -- Open-Source Libraries -- The C++ Standard Library -- Designing a Chess Program -- Requirements -- Design Steps -- Divide the Program into Subsystems -- Choose Threading Models -- Specify Class Hierarchies for Each Subsystem -- Specify Classes, Data Structures, Algorithms, and Patterns for Each Subsystem -- Specify Error Handling for Each Subsystem -- Summary -- Exercises -- Chapter 5: Designing with Objects -- Am I Thinking Procedurally? -- The Object-Oriented Philosophy -- Classes -- Components -- Properties -- Behaviors -- Bringing It All Together -- Living in a World of Classes -- Over-Classification -- Overly General Classes -- Class Relationships -- The Has-a Relationship -- The Is-a Relationship (Inheritance) -- Inheritance Techniques -- Polymorphism -- The Fine Line Between Has-a and Is-a -- The Not-a Relationship -- Hierarchies -- Multiple Inheritance -- Mixin Classes -- Summary -- Exercises -- Chapter 6: Designing for Reuse
  • Cover -- Title Page -- Copyright Page -- Contents -- Introduction -- Part I: Introduction to Professional C++ -- Chapter 1: A Crash Course in C++ and the Standard Library -- C++ Crash Course -- The Obligatory "Hello, World" Program -- Comments -- Importing Modules -- Preprocessor Directives -- The main() Function -- I/O Streams -- Namespaces -- Nested Namespace -- Namespace Alias -- Literals -- Variables -- Numerical Limits -- Zero Initialization -- Casting -- Floating-Point Numbers -- Operators -- Enumerated Types -- Old-Style Enumerated Types -- Structs -- Conditional Statements -- if/else Statements -- switch Statements -- The Conditional Operator -- Logical Evaluation Operators -- Three-Way Comparisons -- Functions -- Function Return Type Deduction -- Current Function's Name -- Function Overloading -- Attributes -- [[nodiscard]] -- [[maybe_unused]] -- [[noreturn]] -- [[deprecated]] -- [[likely]] and [[unlikely]] -- C-Style Arrays -- std::array -- std::vector -- std::pair -- std::optional -- Structured Bindings -- Loops -- The while Loop -- The do/while Loop -- The for Loop -- The Range-Based for Loop -- Initializer Lists -- Strings in C++ -- C++ as an Object-Oriented Language -- Defining Classes -- Using Classes -- Scope Resolution -- Uniform Initialization -- Designated Initializers -- Pointers and Dynamic Memory -- The Stack and the Free Store -- Working with Pointers -- Dynamically Allocated Arrays -- Null Pointer Constant -- The Use of const -- const as a Qualifier for a Type -- const Methods -- The constexpr Keyword -- The consteval Keyword -- References -- Reference Variables -- Reference Data Members -- Reference Parameters -- Reference Return Values -- Deciding Between References and Pointers -- const_cast() -- Exceptions -- Type Aliases -- typedefs -- Type Inference -- The auto Keyword -- The decltype Keyword -- The Standard Library