C++ Initialization Story

C++ Initialization Story

Bartłomiej Filipek
This is a sample of the book's content.Buy on Leanpub

Table of Contents

C++ Initialization Story

  • About the Book
    • Why should you read this book?
    • Learning objectives
    • The structure of the book
    • Who is this book for?
    • Prerequisites
    • Reader feedback & errata
    • Example code
    • Formatting & Layout
  • About the Author
  • Acknowledgements
  • Revision History
  • 1. Local Variables and Simple Types
    • Starting with simple types
    • Setting values to zero
    • Initialization with aggregates
    • Default data member initialization
    • Summary
  • 2. Classes and Initialization With Constructors
    • A simple class type
    • Basics of constructors
    • Body of a constructor
    • Adding constructors to DataPacket
    • Compiler-generated default constructors
    • Explicit constructors
    • Difference between direct and copy initialization
    • Constructor summary
  • 3. Copy and Move Constructors
    • Copy constructor
    • Move constructor
    • Distinguishing from assignment
    • Adding logging to constructors
    • Trivial classes and user-declared/user-provided default constructors
  • 4. Delegating and Inheriting Constructors
    • Limitations
    • Inheritance
    • Inheriting constructors
  • 5. Destructors
    • Basics
    • Objects allocated on the heap
    • Destructors and data members
    • Virtual destructors and polymorphism
    • Partially created objects
    • Use Cases
    • A compiler-generated destructor
  • 6. Initialization and Type Deduction
  • 7. Quiz on Constructors
  • 8. Non-Static Data Member Initialization
    • How it works
    • Investigation
    • Experiments
    • Other forms of NSDMI
    • Copy constructor and NSDMI
    • Move constructor and NSDMI
    • C++14 changes
    • C++20 changes
    • Limitations of NSDMI
    • NSDMI: Advantages and Disadvantages
    • NSDMI summary
    • NSDMI: Exercises
  • 9. Containers as Data Members
    • The basics
    • Using std::initializer list
    • Example implementation
  • 10. Non-regular Data Members
    • Constant non-static data members
    • References as data members
    • Pointers as data members
    • Moveable-only data members
    • Summary
  • 11. Inline Variables in C++17
    • About static data members
    • Motivation for inline variables
    • Exercise for inline variables
    • Global inline variables
    • Constexpr and inline variables
  • 12. Aggregates and Designated Initializers in C++20
    • Aggregates in C++20
    • The basics of Designated Initializers
    • Rules
    • Advantages of designated initialization
    • Examples
    • Summary
    • The summary example
    • Compiler support
  • 13. Techniques and Use Cases
    • Using explicit for strong types
    • Best way to initialize string data members
    • The copy and swap idiom
    • Several initialization types in one class
    • Vector like RAII object
    • Factory with self-registering types
    • Summary
  • 14. The Final Quiz
  • Appendix A - Quiz and Exercises Answers
  • References
  • Notes
C++ Initialization Story/overview

C++ Initialization Story

course_overview

count_chapters
begin_reading
download
p_implied_book_part_name

C++ Initialization Story21 chapters

Begin ›
  1. About the Book

  2. About the Author

  3. Acknowledgements

  4. Revision History

  5. 1. Local Variables and Simple Types

  6. 2. Classes and Initialization With Constructors

  7. 3. Copy and Move Constructors

  8. 4. Delegating and Inheriting Constructors

  9. 5. Destructors

  10. 6. Initialization and Type Deduction

  11. 7. Quiz on Constructors

  12. 8. Non-Static Data Member Initialization

  13. 9. Containers as Data Members

  14. 10. Non-regular Data Members

  15. 11. Inline Variables in C++17

  16. 12. Aggregates and Designated Initializers in C++20

  17. 13. Techniques and Use Cases

  18. 14. The Final Quiz

  19. Appendix A - Quiz and Exercises Answers

  20. References

  21. Notes