Free through lesson 3

C++ for Beginners

From building with clang++ and iostream to classes and RAII, the STL, templates, smart pointers, ranges and threads, and finally CMake and unit tests. Over 50 lessons, you'll get to the point where you "let types manage resource lifetimes, and can build and ship one small tool." Every code sample, compile error, and sanitizer report was actually run with clang++ 21 (C++23).

about 2 hours in total (estimate)

Slides for this course (for classes and in-house training) →

Curriculum

The 50 lessons are split into 7 chapters. We recommend going in order from chapter 1, but feel free to jump to whatever interests you. Note: C++ can't run in the browser, so compile and try the samples locally with clang++ 16 or later, or g++ 13 or later (with C++23 support). The course assumes you know C (pointers and malloc).

Chapter 1 — From C to C++ (lessons 1–7)

You'll rewrite code you could write in C using C++ tools, learning iostream, references, namespaces, auto, range-based for, and overloading along the way. By the end of this chapter, you'll be able to read and write C code as C++.

1

Your First Steps in C++ (Building with clang++)

Just the differences a C programmer hits first: building with clang++, Hello World with iostream, how it differs from printf, and the one spot where C code stops compiling as C++.

about 3 min Free preview Free
2

std::string and I/O

Freedom from managing char arrays and '\0'. Concatenation, comparison, substrings, reading a line, and measuring why you shouldn't write std::endl on every line.

about 3 min Free
3

References (&): Modifying Without Writing Pointers

Rewrite C's "modify the caller" functions, full of & and *, with references. Check addresses to see a reference is a non-rebindable alias and that const references avoid copies.

about 2 min Free
4

Namespaces and using

Create a clash between functions with the same name, then wrap them in a namespace. Why to avoid using namespace std, namespace aliases, and anonymous namespaces as a replacement for C's static.

about 2 min 🔒 Basic
5

auto and Range-Based for

auto lets you skip writing type names, and range-based for replaces index loops. Forgetting auto & makes a copy, and auto can pick up a type you didn't intend.

about 2 min 🔒 Basic
6

Function Overloading and Default Arguments

Provide a same-named function for each type. The order in which one is chosen, cases that stop as ambiguous, and accidents when combined with default arguments.

about 2 min 🔒 Basic
7

nullptr, enum class, and Structured Bindings

Replace risky habits inherited from C with C++ alternatives. NULL vs nullptr, typed enumerations, and structured bindings for receiving two return values.

about 2 min 🔒 Basic

Chapter 2 — Classes and RAII (lessons 8–14)

You'll bundle data and behavior into classes, and let constructors and destructors tie resource lifetimes to types. Then you'll cover copying, moving, and operator overloading, ending with types you wrote yourself that work naturally with = and +.

Chapter 3 — STL (lessons 15–22)

You'll learn vector, map, and set, plus the iterators and algorithms that cut across all of them. Loops you used to write by hand become a single line from <algorithm>, and lambdas let you pass "how to compare" right on the spot.

15

std::vector Basics

Replace the "growable array" you built with malloc and realloc. Adding, accessing, and removing, what happens when you go out of range, and making a 2D vector.

about 2 min 🔒 Basic
16

How vector Grows (capacity and reserve)

Measure the difference between size and capacity. How many reallocations happen, how much faster reserve makes things, and a sanitizer catching references invalidated by reallocation.

about 2 min 🔒 Basic
17

std::map and std::unordered_map

Containers you look up by key. Ordered map vs fast unordered_map, the trap where [] silently creates elements, and when to use contains vs find.

about 2 min 🔒 Basic
18

std::set and Removing Duplicates

A container that drops duplicates and keeps things sorted just by inserting. Use insert's return value to tell if something was new, define your own ordering, and choose vs unordered_set.

about 2 min 🔒 Basic
19

Iterators

A common tool for walking through any container. Half-open ranges with begin and end, the link to pointers, what each kind can do, and invalidation.

about 2 min 🔒 Basic
20

The <algorithm> Essentials

Turn hand-written loops into one line. Sorting, searching, counting, summing, the erase-remove idiom, and binary search.

about 2 min 🔒 Basic
21

Lambda Expressions

Small functions written on the spot. Syntax, capture by value vs by reference, mutable, return types, lifetime traps, and std::function.

about 2 min 🔒 Basic
22

Combining Algorithms and Lambdas

Using sales data, chain sorting, filtering, transforming, and aggregating. back_inserter and transform, binary operations for accumulate, and stable sorting.

about 2 min 🔒 Basic

Chapter 4 — Templates (lessons 23–29)

Stop copying the same logic for every type and fold it into one template. You'll cover specialization, parameter packs, constexpr, and concepts, and get to the point where you can read template errors on your own.

Chapter 5 — Memory and Ownership (lessons 30–36)

First you'll actually break things with new and delete, then replace them with unique_ptr and shared_ptr. You'll learn to write code that doesn't leak resources even when exceptions fly, and finish by checking the Rule of Five with a string class you write yourself.

30

new and delete, and the Trouble with Raw Pointers

Turning malloc and free into new and delete solves nothing. Forgetting [], forgetting to free, and the root problem: "who frees this?" can't be expressed in the type.

about 2 min 🔒 Basic
31

unique_ptr

Write "exactly one owner" into the type. make_unique, move-only (no copying), use in function parameters and return values, and custom cleanup.

about 2 min 🔒 Basic
32

shared_ptr and weak_ptr

Reference counting for multiple owners. How use_count changes, leaks from cyclic references, breaking the cycle with weak_ptr, and why to use make_shared.

about 2 min 🔒 Basic
33

Exceptions (throw, try, catch)

Throw errors you can't report through return values. The std::exception family, why to catch by const reference, custom exceptions, and destructors running during unwinding.

about 2 min 🔒 Basic
34

Exception Safety and RAII

Code that doesn't break when exceptions fly. Plug leaks from new with unique_ptr, tell the basic guarantee from the strong one, and tidy up with copy-and-swap.

about 2 min 🔒 Basic
35

Building Data Structures with Smart Pointers

Write a binary search tree with unique_ptr. Children are owned; the parent is only borrowed. Search, insert, traversal, and the recursion depth problem in destructors.

about 2 min 🔒 Basic
36

[Project] Build a Small String Class

Write the Rule of Five all by hand. Count allocations, copies, moves, and frees to verify behavior, then see why you'd still use std::string.

about 2 min 🔒 Basic

Chapter 6 — Modern C++ (lessons 37–44)

This chapter covers optional, variant, string_view, span, and ranges, plus threads and synchronization. You'll express "a value that might be missing" and "exactly one of several types" with types, and run multiple tasks at the same time.

37

std::optional

Express "there might be no value" with a type. Drop conventions like null pointers or -1; use has_value and value_or, and learn the rules for getting the value out.

about 3 min 🔒 Basic
38

std::variant and std::visit

Safely hold "exactly one of several types." How it differs from union, index and get, branching with visit, and monostate.

about 2 min 🔒 Basic
39

string_view and span

Pass a "look but don't copy" view. Slice substrings with string_view, accept arrays and vectors the same way with span, and watch out for lifetimes.

about 2 min 🔒 Basic
40

ranges Basics

No more writing both begin and end. std::ranges algorithms, projections, and a first look at the idea of views.

about 2 min 🔒 Basic
41

Combining ranges Views

Chain take, drop, split, join, enumerate, and zip to write aggregation as a single pipeline. Infinite ranges, and when you must not return a view.

about 3 min 🔒 Basic
42

std::thread

Run work at the same time. Creating a thread and join, passing arguments, hardware_concurrency, and measuring how touching the same variable breaks things.

about 2 min 🔒 Basic
43

mutex and Mutual Exclusion

Stop data races. lock_guard and scoped_lock, when atomic is enough, how deadlocks happen and how to avoid them, and the strongest move of all: don't share.

about 2 min 🔒 Basic
44

std::async and future

Get results without touching threads directly. async launch policies, future's get, how exceptions propagate, and passing values yourself with promise.

about 2 min 🔒 Basic

Chapter 7 — Building It for Real (lessons 45–50)

You'll put together header splitting, CMake, unit tests, and sanitizers to finish one small tool. Finally, we'll line up the differences from C and Rust and hand you a map of where to go next.

Once you've finished all 50 lessons, move on to Rust for Beginners, where the compiler watches ownership for you; the C Intro Course, the foundation C++ is built on; or Intro to Shipping and Running a Service, to ship what you build. A membership unlocks every course.