O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Professional C++, 4th Edition

Book Description

Get up to date quickly on the new changes coming with C++17

Professional C++ 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 that you can plug into your own applications. Case studies include extensive, working code that has been tested on Windows and Linux, and the author's expert tips, tricks, and workarounds can dramatically enhance your workflow. Even many experienced developers have never fully explored the boundaries of the language's capabilities; this book reveals the advanced features you never knew about, and drills down to show you how to turn these features into real-world solutions.

The C++17 release includes changes that impact the way you work with C++; this new fourth edition covers them all, including nested namespaces, structured bindings, string_view, template argument deduction for constructors, parallel algorithms, generalized sum algorithms, Boyer-Moore string searching, string conversion primitives, a filesystem API, clamping values, optional values, the variant type, the any type, and more. Clear explanations and professional-level depth make this book an invaluable resource for any professional needing to get up to date quickly.

  • Maximize C++ capabilities with effective design solutions
  • Master little-known elements and learn what to avoid
  • Adopt new workarounds and testing/debugging best practices
  • Utilize real-world program segments in your own applications

C++ is notoriously complex, and whether you use it for gaming or business, maximizing its functionality means keeping up to date with the latest changes. Whether these changes enhance your work or make it harder depends on how well-versed you are in the newest C++ features. Professional C++ gets you up to date quickly, and provides the answers you need for everyday solutions.

Table of Contents

  1. COVER
  2. TITLE PAGE
  3. INTRODUCTION
    1. WHO THIS BOOK IS FOR
    2. WHAT THIS BOOK COVERS
    3. HOW THIS BOOK IS STRUCTURED
    4. WHAT YOU NEED TO USE THIS BOOK
    5. CONVENTIONS
    6. SOURCE CODE
    7. ERRATA
    8. NOTES
  4. PART I: Introduction to Professional C++
    1. 1 A Crash Course in C++ and the Standard Library
      1. THE BASICS OF C++
      2. DIVING DEEPER INTO C++
      3. C++ AS AN OBJECT-ORIENTED LANGUAGE
      4. UNIFORM INITIALIZATION
      5. THE STANDARD LIBRARY
      6. YOUR FIRST USEFUL C++ PROGRAM
      7. SUMMARY
      8. NOTE
    2. 2 Working with Strings and String Views
      1. DYNAMIC STRINGS
      2. SUMMARY
    3. 3 Coding with Style
      1. THE IMPORTANCE OF LOOKING GOOD
      2. DOCUMENTING YOUR CODE
      3. DECOMPOSITION
      4. NAMING
      5. USING LANGUAGE FEATURES WITH STYLE
      6. FORMATTING
      7. STYLISTIC CHALLENGES
      8. SUMMARY
  5. PART II: Professional C++ Software Design
    1. 4 Designing Professional C++ Programs
      1. WHAT IS PROGRAMMING DESIGN?
      2. THE IMPORTANCE OF PROGRAMMING DESIGN
      3. DESIGNING FOR C++
      4. TWO RULES FOR C++ DESIGN
      5. REUSING EXISTING CODE
      6. DESIGNING A CHESS PROGRAM
      7. SUMMARY
    2. 5 Designing with Objects
      1. AM I THINKING PROCEDURALLY?
      2. THE OBJECT-ORIENTED PHILOSOPHY
      3. LIVING IN A WORLD OF OBJECTS
      4. OBJECT RELATIONSHIPS
      5. ABSTRACTION
      6. SUMMARY
    3. 6 Designing for Reuse
      1. THE REUSE PHILOSOPHY
      2. HOW TO DESIGN REUSABLE CODE
      3. SUMMARY
  6. PART III: C++ Coding the Professional Way
    1. 7 Memory Management
      1. WORKING WITH DYNAMIC MEMORY
      2. ARRAY-POINTER DUALITY
      3. LOW-LEVEL MEMORY OPERATIONS
      4. SMART POINTERS
      5. COMMON MEMORY PITFALLS
      6. SUMMARY
      7. NOTE
    2. 8 Gaining Proficiency with Classes and Objects
      1. INTRODUCING THE SPREADSHEET EXAMPLE
      2. WRITING CLASSES
      3. OBJECT LIFE CYCLES
      4. SUMMARY
    3. 9 Mastering Classes and Objects
      1. FRIENDS
      2. DYNAMIC MEMORY ALLOCATION IN OBJECTS
      3. MORE ABOUT METHODS
      4. DIFFERENT KINDS OF DATA MEMBERS
      5. NESTED CLASSES
      6. ENUMERATED TYPES INSIDE CLASSES
      7. OPERATOR OVERLOADING
      8. BUILDING STABLE INTERFACES
      9. SUMMARY
    4. 10 Discovering Inheritance Techniques
      1. BUILDING CLASSES WITH INHERITANCE
      2. INHERITANCE FOR REUSE
      3. RESPECT YOUR PARENTS
      4. INHERITANCE FOR POLYMORPHISM
      5. MULTIPLE INHERITANCE
      6. INTERESTING AND OBSCURE INHERITANCE ISSUES
      7. SUMMARY
    5. 11 C++ Quirks, Oddities, and Incidentals
      1. REFERENCES
      2. KEYWORD CONFUSION
      3. TYPES AND CASTS
      4. SCOPE RESOLUTION
      5. ATTRIBUTES
      6. USER-DEFINED LITERALS
      7. HEADER FILES
      8. C UTILITIES
      9. SUMMARY
      10. NOTES
    6. 12 Writing Generic Code with Templates
      1. OVERVIEW OF TEMPLATES
      2. CLASS TEMPLATES
      3. FUNCTION TEMPLATES
      4. VARIABLE TEMPLATES
      5. SUMMARY
    7. 13 Demystifying C++ I/O
      1. USING STREAMS
      2. STRING STREAMS
      3. FILE STREAMS
      4. BIDIRECTIONAL I/O
      5. SUMMARY
    8. 14 Handling Errors
      1. ERRORS AND EXCEPTIONS
      2. EXCEPTION MECHANICS
      3. EXCEPTIONS AND POLYMORPHISM
      4. RETHROWING EXCEPTIONS
      5. STACK UNWINDING AND CLEANUP
      6. COMMON ERROR-HANDLING ISSUES
      7. PUTTING IT ALL TOGETHER
      8. SUMMARY
      9. NOTES
    9. 15 Overloading C++ Operators
      1. OVERVIEW OF OPERATOR OVERLOADING
      2. OVERLOADING THE ARITHMETIC OPERATORS
      3. OVERLOADING THE BITWISE AND BINARY LOGICAL OPERATORS
      4. OVERLOADING THE INSERTION AND EXTRACTION OPERATORS
      5. OVERLOADING THE SUBSCRIPTING OPERATOR
      6. OVERLOADING THE FUNCTION CALL OPERATOR
      7. OVERLOADING THE DEREFERENCING OPERATORS
      8. WRITING CONVERSION OPERATORS
      9. OVERLOADING THE MEMORY ALLOCATION AND DEALLOCATION OPERATORS
      10. SUMMARY
      11. NOTE
    10. 16 Overview of the C++ Standard Library
      1. CODING PRINCIPLES
      2. OVERVIEW OF THE C++ STANDARD LIBRARY
      3. SUMMARY
      4. NOTE
    11. 17 Understanding Containers and Iterators
      1. CONTAINERS OVERVIEW
      2. SEQUENTIAL CONTAINERS
      3. CONTAINER ADAPTORS
      4. ORDERED ASSOCIATIVE CONTAINERS
      5. UNORDERED ASSOCIATIVE CONTAINERS OR HASH TABLES
      6. OTHER CONTAINERS
      7. SUMMARY
    12. 18 Mastering Standard Library Algorithms
      1. OVERVIEW OF ALGORITHMS
      2. STD::FUNCTION
      3. LAMBDA EXPRESSIONS
      4. FUNCTION OBJECTS
      5. ALGORITHM DETAILS
      6. ALGORITHMS EXAMPLE: AUDITING VOTER REGISTRATIONS
      7. SUMMARY
      8. NOTE
    13. 19 String Localization and Regular Expressions
      1. LOCALIZATION
      2. REGULAR EXPRESSIONS
      3. SUMMARY
    14. 20 Additional Library Utilities
      1. RATIOS
      2. THE CHRONO LIBRARY
      3. RANDOM NUMBER GENERATION
      4. OPTIONAL
      5. VARIANT
      6. ANY
      7. TUPLES
      8. FILESYSTEM SUPPORT LIBRARY
      9. SUMMARY
      10. NOTE
  7. PART IV: Mastering Advanced Features of C++
    1. 21 Customizing and Extending the Standard Library
      1. ALLOCATORS
      2. STREAM ITERATORS
      3. ITERATOR ADAPTORS
      4. EXTENDING THE STANDARD LIBRARY
      5. SUMMARY
      6. NOTE
    2. 22 Advanced Templates
      1. MORE ABOUT TEMPLATE PARAMETERS
      2. CLASS TEMPLATE PARTIAL SPECIALIZATION
      3. EMULATING FUNCTION PARTIAL SPECIALIZATION WITH OVERLOADING
      4. TEMPLATE RECURSION
      5. VARIADIC TEMPLATES
      6. METAPROGRAMMING
      7. SUMMARY
    3. 23 Multithreaded Programming with C++
      1. INTRODUCTION
      2. THREADS
      3. ATOMIC OPERATIONS LIBRARY
      4. MUTUAL EXCLUSION
      5. CONDITION VARIABLES
      6. FUTURES
      7. EXAMPLE: MULTITHREADED LOGGER CLASS
      8. THREAD POOLS
      9. THREADING DESIGN AND BEST PRACTICES
      10. SUMMARY
      11. NOTES
  8. PART V: C++ Software Engineering
    1. 24 Maximizing Software Engineering Methods
      1. THE NEED FOR PROCESS
      2. SOFTWARE LIFE CYCLE MODELS
      3. SOFTWARE ENGINEERING METHODOLOGIES
      4. BUILDING YOUR OWN PROCESS AND METHODOLOGY
      5. SOURCE CODE CONTROL
      6. SUMMARY
    2. 25 Writing Efficient C++
      1. OVERVIEW OF PERFORMANCE AND EFFICIENCY
      2. LANGUAGE-LEVEL EFFICIENCY
      3. DESIGN-LEVEL EFFICIENCY
      4. PROFILING
      5. SUMMARY
    3. 26 Becoming Adept at Testing
      1. QUALITY CONTROL
      2. UNIT TESTING
      3. HIGHER-LEVEL TESTING
      4. TIPS FOR SUCCESSFUL TESTING
      5. SUMMARY
      6. NOTES
    4. 27 Conquering Debugging
      1. THE FUNDAMENTAL LAW OF DEBUGGING
      2. BUG TAXONOMIES
      3. AVOIDING BUGS
      4. PLANNING FOR BUGS
      5. STATIC ASSERTIONS
      6. DEBUGGING TECHNIQUES
      7. SUMMARY
      8. NOTES
    5. 28 Incorporating Design Techniques and Frameworks
      1. “I CAN NEVER REMEMBER HOW TO…”
      2. THERE MUST BE A BETTER WAY
      3. OBJECT-ORIENTED FRAMEWORKS
      4. SUMMARY
    6. 29 Applying Design Patterns
      1. THE ITERATOR PATTERN
      2. THE SINGLETON PATTERN
      3. THE ABSTRACT FACTORY PATTERN
      4. THE PROXY PATTERN
      5. THE ADAPTOR PATTERN
      6. THE DECORATOR PATTERN
      7. THE CHAIN OF RESPONSIBILITY PATTERN
      8. THE OBSERVER PATTERN
      9. SUMMARY
      10. NOTE
    7. 30 Developing Cross-Platform and Cross-Language Applications
      1. CROSS-PLATFORM DEVELOPMENT
      2. CROSS-LANGUAGE DEVELOPMENT
      3. SUMMARY
  9. A: C++ Interviews
    1. CHAPTER 1: A CRASH COURSE IN C++ AND THE STANDARD LIBRARY
    2. CHAPTERS 2 AND 19: WORKING WITH STRINGS AND STRING VIEWS, STRING LOCALIZATION, AND REGULAR EXPRESSIONS
    3. CHAPTER 3: CODING WITH STYLE
    4. CHAPTER 4: DESIGNING PROFESSIONAL C++ PROGRAMS
    5. CHAPTER 5: DESIGNING WITH OBJECTS
    6. CHAPTER 6: DESIGNING FOR REUSE
    7. CHAPTER 7: MEMORY MANAGEMENT
    8. CHAPTERS 8 AND 9: GAINING PROFICIENCY WITH CLASSES AND OBJECTS, AND MASTERING CLASSES AND OBJECTS
    9. CHAPTER 10: DISCOVERING INHERITANCE TECHNIQUES
    10. CHAPTER 11: C++ QUIRKS, ODDITIES, AND INCIDENTALS
    11. CHAPTERS 12 AND 22: WRITING GENERIC CODE WITH TEMPLATES, AND ADVANCED TEMPLATES
    12. CHAPTER 13: DEMYSTIFYING C++ I/O
    13. CHAPTER 14: HANDLING ERRORS
    14. CHAPTER 15: OVERLOADING C++ OPERATORS
    15. CHAPTERS 16, 17, 18, AND 21: THE STANDARD LIBRARY
    16. CHAPTER 20: ADDITIONAL LIBRARY UTILITIES
    17. CHAPTER 23: MULTITHREADED PROGRAMMING WITH C++
    18. CHAPTER 24: MAXIMIZING SOFTWARE ENGINEERING METHODS
    19. CHAPTER 25: WRITING EFFICIENT C++
    20. CHAPTER 26: BECOMING ADEPT AT TESTING
    21. CHAPTER 27: CONQUERING DEBUGGING
    22. CHAPTER 28: INCORPORATING DESIGN TECHNIQUES AND FRAMEWORKS
    23. CHAPTER 29: APPLYING DESIGN PATTERNS
    24. CHAPTER 30: DEVELOPING CROSS-PLATFORM AND CROSS-LANGUAGE APPLICATIONS
  10. B: Annotated Bibliography
    1. C++
    2. UNIFIED MODELING LANGUAGE
    3. ALGORITHMS AND DATA STRUCTURES
    4. RANDOM NUMBERS
    5. OPEN-SOURCE SOFTWARE
    6. SOFTWARE ENGINEERING METHODOLOGY
    7. PROGRAMMING STYLE
    8. COMPUTER ARCHITECTURE
    9. EFFICIENCY
    10. TESTING
    11. DEBUGGING
    12. DESIGN PATTERNS
    13. OPERATING SYSTEMS
    14. MULTITHREADED PROGRAMMING
  11. C: Standard Library Header Files
    1. THE C STANDARD LIBRARY
    2. CONTAINERS
    3. ALGORITHMS, ITERATORS, AND ALLOCATORS
    4. GENERAL UTILITIES
    5. MATHEMATICAL UTILITIES
    6. EXCEPTIONS
    7. I/O STREAMS
    8. THREADING SUPPORT LIBRARY
  12. D: Introduction to UML
    1. TYPES OF DIAGRAMS
    2. CLASS DIAGRAMS
  13. END USER LICENSE AGREEMENT