Class Layout
This page explains how the class features you write — members, virtual functions, inheritance —
Access Control
Access control (public, private, protected) enables encapsulation by controlling which code can access class members.
Constructors & Destructors
Constructors initialize objects and allocate resources. Destructors clean up when objects are destroyed. Together they enable RAII (Resource Acquisition Is Initialization).
Rule of 0/3/5
These rules tell you which special member functions to define based on your class's resource management needs.
Copy & Move
Copy creates a duplicate of an object. Move transfers ownership of resources from one object to another. Understanding when each happens is crucial for performance and correctness.
Inheritance
Inheritance lets you create new classes based on existing ones, reusing code and establishing "is-a" relationships. Derived classes inherit members from base classes and can add new functionality or override existing behavior.
Multiple Inheritance
Multiple inheritance allows a class to inherit from multiple base classes. This enables combining functionality but introduces complexity, especially the diamond problem.
Lambdas
Lambdas (C++11) are anonymous functions that can capture variables from surrounding scope, enabling functional programming patterns and convenient callbacks.
Virtual Functions & vtables
Virtual functions enable runtime polymorphism through dynamic dispatch. Understanding how they work (vtables) helps you understand their cost and use them effectively.
Dynamic vs Static Polymorphism
C++ supports two forms of polymorphism: dynamic (runtime, using virtual functions) and static (compile-time, using templates). Each has different trade-offs.
Object Slicing
Object slicing occurs when you copy a derived class object to a base class object. The derived parts are "sliced off" and lost.