Complete C++ Programming Study Guide
Why This Guide Exists
Section titled “Why This Guide Exists”C++ is one of the most powerful and complex programming languages in existence. It gives you direct control over memory, performance, and hardware — but that power comes with a steep learning curve. This hub page maps every resource on this site and provides a learning path so you can build competence systematically.
These notes cover modern C++ (C++20/23) — the version of the language used in production today. Every concept includes worked code examples, common pitfalls, and the best practices that experienced developers rely on. The goal is not just to write code that compiles, but to write code that is correct, maintainable, and performant.
Table of Contents
Section titled “Table of Contents”- Learning Path
- Types
- Resource Management
- Object-Oriented Programming
- Templates and Metaprogramming
- Standard Library
- Concurrency
- Function Architecture
- Cross-Site Resources
- FAQ
Learning Path
Section titled “Learning Path”C++ topics are deeply interconnected. The following path reflects the dependencies — study the listed prerequisites before moving on.
Phase 1: Foundations (Weeks 1–4)
Section titled “Phase 1: Foundations (Weeks 1–4)”Start here. These topics form the basis of every C++ program you will write.
- Types — data layout, pointers, references, and initialization
- Resource Management — ownership, RAII, and move semantics
Phase 2: Abstraction (Weeks 5–8)
Section titled “Phase 2: Abstraction (Weeks 5–8)”Learn to build abstractions that hide complexity and express intent.
- Object-Oriented Programming — class design, polymorphism, and vtables
- Function Architecture — overload resolution, lambdas, and error handling
Phase 3: Generic Programming (Weeks 9–12)
Section titled “Phase 3: Generic Programming (Weeks 9–12)”Write code that works across types while remaining type-safe.
- Templates and Metaprogramming — generic programming, concepts, and compile-time computation
- Standard Library — containers, algorithms, ranges, and I/O
Phase 4: Advanced (Weeks 13–16)
Section titled “Phase 4: Advanced (Weeks 13–16)”Master the topics that distinguish professional C++ developers.
- Concurrency — threads, atomics, coroutines, and the memory model
Dependency Diagram
Section titled “Dependency Diagram”Types └── Resource Management (RAII, move semantics) ├── Object-Oriented Programming (class design, polymorphism) │ └── Function Architecture (lambdas, type erasure) ├── Templates and Metaprogramming (generic programming) │ └── Standard Library (containers, algorithms) └── Concurrency (threads, atomics)C++ is a statically typed language — understanding how types work at the memory level is essential for writing correct, performant code. This section covers data layout, pointers, references, and the rules that govern object lifetime.
Topics
Section titled “Topics”- Data Layout — object size, alignment, padding, and struct layout
- Pointers, References, and Views — raw pointers, smart pointers, and non-owning views
- Initialization and Lifetime — default initialization, value initialization, and object lifetime rules
Why This Matters
Section titled “Why This Matters”Every C++ bug ultimately traces back to incorrect type usage or violated lifetime assumptions. Understanding data layout prevents buffer overflows. Understanding initialization prevents undefined behaviour. Understanding references versus pointers prevents dangling references.
Key Concepts
Section titled “Key Concepts”| Concept | What It Means | Common Mistake |
|---|---|---|
| Alignment | Objects must start at addresses that are multiples of their alignment | Assuming sizeof(struct) is the sum of member sizes |
| Padding | Compilers insert bytes to satisfy alignment requirements | Ignoring padding when calculating memory usage |
| Value initialization | T{} zero-initialises; T() default-initialises | Assuming T x; is the same as T x{}; |
| Lifetime | Objects begin existing when construction completes and end when destruction begins | Accessing an object after its destructor runs |
Resource Management
Section titled “Resource Management”C++ avoids garbage collection in favour of RAII (Resource Acquisition Is Initialization) — resources are tied to object lifetimes. This section covers ownership, smart pointers, move semantics, and the value category system that makes zero-cost abstractions possible.
Topics
Section titled “Topics”- RAII Patterns — deterministic resource management through object lifetimes
- unique_ptr — exclusive ownership with zero overhead
- shared_ptr — reference-counted shared ownership
- weak_ptr — breaking reference cycles
- Custom Deleters — non-standard resource cleanup
- Value Taxonomy — lvalues, rvalues, and the value category system
- Reference Collapsing — how references compose in templates
- Temporary Materialization — when temporaries become objects
- Move Constructors and RVO — transferring ownership without copies
- Return Value Optimisation — compiler elision of copies
Why This Matters
Section titled “Why This Matters”Memory management is the number one source of bugs in C++. RAII eliminates entire categories of resource leaks. Move semantics make zero-cost abstractions possible — you can return large objects from functions without copying them.
Key Patterns
Section titled “Key Patterns”// RAII: resource is released when the object goes out of scope{ auto file = std::ifstream("data.txt"); // file opens here // ... use file ...} // file closes here automatically
// Move semantics: transfer ownership without copyingstd::vector<int> create_data() { std::vector<int> result = {1, 2, 3, 4, 5}; return result; // move or RVO — no copy}Object-Oriented Programming
Section titled “Object-Oriented Programming”C++ supports multiple inheritance, virtual dispatch, and RTTI — powerful features that are easy to misuse. This section covers class design, polymorphism, and the implementation details (vtables, dynamic_cast) that determine performance and correctness.
Class Design
Section titled “Class Design”- Object Layout and vptr — how objects are laid out in memory and how vtables work
- Access Control — public, protected, private, and friend
- Special Member Functions — constructors, destructors, copy, and move operations
- Operator Overloading — when and how to overload operators
- Spaceship Operator — C++20 three-way comparison
- std::formatter — C++20 user-defined formatting
Runtime Polymorphism
Section titled “Runtime Polymorphism”- VTables — how virtual dispatch works under the hood
- Inheritance and Slicing — the object slicing problem and how to avoid it
- Devirtualization — how compilers eliminate virtual call overhead
- RTTI and dynamic_cast — runtime type identification and its costs
- Deducing This and CRTP — C++23 deducing this and the Curiously Recurring Template Pattern
Design Guidelines
Section titled “Design Guidelines”| Principle | Rule | Example |
|---|---|---|
| Rule of Five | If you define any of destructor, copy/move constructor, or copy/move assignment, define all five | RAII classes with raw pointers |
| Rule of Zero | If possible, let the compiler generate all special member functions | Use std::string, std::vector instead of raw arrays |
| Prefer composition | Use inheritance only for “is-a” relationships | A Dog is-an Animal; a Car has-an Engine |
| Avoid public data members | Encapsulate invariants | Use getters/setters or public interface |
Templates and Metaprogramming
Section titled “Templates and Metaprogramming”Templates are C++‘s mechanism for generic programming — writing code that works across types while remaining type-safe. Modern C++ (C++20) adds concepts, ranges, and compile-time computation.
Generic Programming
Section titled “Generic Programming”- Instantiation — how templates are instantiated and the cost of implicit generation
- Argument Deduction — how the compiler deduces template arguments
- Specialization — full and partial template specialisation
- Dependent Names —
typenameandtemplatekeywords in dependent contexts - Explicit Instantiation — controlling template instantiation
Concepts and Constraints
Section titled “Concepts and Constraints”- Defining Concepts — constraining templates with requirements
- Constraint Subsumption — how constraints compose
- Standard Concepts — the concepts library in C++20
- SFINAE vs Concepts — when to use which
Compile-Time Computation
Section titled “Compile-Time Computation”- Parameter Packs — variadic templates and pack expansion
- Fold Expressions — C++17 fold expressions over parameter packs
- if constexpr — compile-time branching
- Type Traits — querying and transforming types at compile time
Standard Library
Section titled “Standard Library”The C++ standard library provides containers, algorithms, iterators, and utilities that form the backbone of idiomatic C++. Modern C++ (C++20) adds ranges, concepts, and parallel algorithms.
Containers and Allocators
Section titled “Containers and Allocators”- Sequence Containers —
vector,deque,list,forward_list,array - Associative Containers —
set,map,multiset,multimap - Iterators — iterator categories, traits, and adaptor patterns
- Polymorphic Memory Resources — custom allocators and memory pools
Algorithms and Ranges
Section titled “Algorithms and Ranges”- Iterator-Sentinel Pairs — the modern iterator model
- Range Adaptors —
views::filter,views::transform, and composition - Projections — C++23 projections for sorting and algorithms
- Range Materialization —
ranges::toand range constructors - Parallel Algorithms —
std::execution::parand GPU execution
I/O and Formatting
Section titled “I/O and Formatting”- Stream Buffers — the underlying buffer model for I/O streams
- Type-Safe Formatting — C++20
std::format - Unicode Support —
char8_t,char16_t, and encoding
System Utilities
Section titled “System Utilities”- Filesystem —
std::filesystemfor portable file operations - Chrono — date and time handling
- Random Numbers — engines, distributions, and seeding
- Regular Expressions —
std::regexand pattern matching
Concurrency
Section titled “Concurrency”C++ concurrency covers threads, synchronisation primitives, the memory model, atomic operations, and coroutines. Writing correct concurrent code requires understanding both the hardware (cache coherency, memory ordering) and the language guarantees.
Threading and Synchronisation
Section titled “Threading and Synchronisation”- Threads and jthread —
std::threadand C++20std::jthread - Data Races — what they are, why they happen, and how to detect them
- Mutexes and Deadlocks —
std::mutex,std::lock_guard, and deadlock prevention - Condition Variables —
std::condition_variableand wait patterns - Thread-Local Storage —
thread_localand its costs
Memory Model and Atomics
Section titled “Memory Model and Atomics”- Instruction Reordering — compiler and hardware reordering
- Cache Coherency — how multi-core systems maintain consistency
- Atomic Operations —
std::atomicand atomic operations - Memory Orderings —
relaxed,acquire,release,seq_cst - CAS Loops — compare-and-swap patterns for lock-free programming
Coroutines and Async I/O
Section titled “Coroutines and Async I/O”- Coroutine Frames — the underlying mechanism of C++20 coroutines
- Promise and Awaiter — controlling coroutine behaviour
- Generators — producing sequences lazily
- Task Scheduling — scheduling coroutine execution
- Futures and Promises —
std::futureandstd::promise
Function Architecture
Section titled “Function Architecture”Functions are the building blocks of C++ programs. This section covers overload resolution, calling conventions, lambdas, type erasure, error handling, and C interop — the design decisions that determine how your code is structured and how it behaves.
Function Mechanics
Section titled “Function Mechanics”- Overload Resolution — how the compiler selects the best function
- Calling Conventions —
__cdecl,__stdcall, and the impact on ABI - Lambdas — closure types, capture lists, and generic lambdas
- Type Erasure —
std::function, virtual dispatch, and the pattern - C Interop —
extern "C", ABI compatibility, and calling C from C++
Error Handling
Section titled “Error Handling”- Exception ABI — how exceptions propagate and their cost
- Exception Safety — basic, strong, and no-throw guarantees
- noexcept — specifying and checking exception safety
- std::optional and std::variant — representing optional values and sum types
- std::expected — C++23 error handling without exceptions
Cross-Site Resources
Section titled “Cross-Site Resources”Programming connects to theory and applied fields:
- University Mathematics — linear algebra, discrete mathematics, and probability theory underpin algorithms and computational geometry
- University Physics — computational physics, numerical methods, and simulation require C++ skills
- IB Computer Science — introductory programming concepts at the IB level
- DSE ICT — secondary-level computing for the Hong Kong DSE
Frequently Asked Questions
Section titled “Frequently Asked Questions”How long does it take to learn C++ well?
Section titled “How long does it take to learn C++ well?”C++ is a large language. Most developers become productive in 3–6 months and proficient in 2–3 years. These notes are designed for university-level students with some prior programming experience. If you are completely new to programming, start with a simpler language (Python, JavaScript) before tackling C++.
Which version of C++ should I use?
Section titled “Which version of C++ should I use?”These notes cover C++20 and C++23 — the current standard. Use a recent compiler (GCC 13+, Clang 17+, MSVC 19.38+) to access modern features like concepts, ranges, coroutines, and std::format.
Should I learn C before C++?
Section titled “Should I learn C before C++?”No. Modern C++ is a different language from C, and learning C habits first can make C++ harder to learn. Start with modern C++ idioms: RAII, smart pointers, containers, algorithms, and lambdas.
How do I debug C++ code?
Section titled “How do I debug C++ code?”Start with the compiler’s warnings — enable -Wall -Wextra -Wpedantic and treat warnings as errors. Use AddressSanitizer (-fsanitize=address) to catch memory errors. For undefined behaviour, use UndefinedBehaviorSanitizer. For performance, use Valgrind or perf.
What is the most important C++ concept?
Section titled “What is the most important C++ concept?”RAII (Resource Acquisition Is Initialization). If you understand RAII — that resource lifetimes are tied to object lifetimes — you will avoid most common C++ bugs: memory leaks, dangling pointers, and resource handles left open.
Are these notes suitable for self-study?
Section titled “Are these notes suitable for self-study?”Yes. Each section includes worked code examples, common pitfalls, and best practices. Compile and run every example — do not just read the code. Then attempt the exercises to test your understanding.
Last updated: 24 July 2026
Written by Wyatt. For questions or feedback, visit wyattau.com.