C++ Course

C++ powers game engines, browsers, databases, finance systems and much of the software where speed matters. This course teaches modern C++ — C++20, with the newest C++23 additions — from your first program through containers, algorithms, classes, templates and concepts to multi-file projects, finishing with a complete library-catalogue application. It focuses on the safe, expressive style professionals use today: values, RAII, smart pointers and the standard library.

What you'll learn

The course has 53 lessons in ten parts:

  • Getting Started — what C++ is, installing a compiler, and your first program.
  • Basics — types, auto, constants and constexpr, operators, streams, std::string, conversions, conditions and loops.
  • Functions — references, choosing how to pass arguments, move semantics, overloading and namespaces.
  • Containers — std::array, std::vector, string_view and span, structs and enum class, maps, sets, queues and iterators.
  • Algorithms & Lambdas — lambdas, the standard algorithms, and C++20 ranges and views.
  • Memory & Resources — pointers, new/delete and why to avoid them, smart pointers and RAII.
  • Object-Oriented Programming — classes, constructors, operator overloading, copy and move, inheritance, polymorphism and interfaces.
  • Templates — function and class templates, and constraining them with concepts.
  • Errors & the Standard Library — exceptions, optional/variant/expected, files, std::format, random numbers, dates and threads.
  • Projects & Modern C++ — headers, CMake, C++23, safety and sanitizers, testing, and a final project.

Every example in the course was compiled with Clang using -std=c++20 -Wall -Wextra -pedantic (and -std=c++23 where marked) and run, and the output shown is exactly what it printed. Examples compile without warnings, except where a lesson shows a warning or error on purpose. The Try it yourself editors let you change any example and copy it to compile on your own computer.

No previous experience with C++ is required. Some programming experience — in any language, or our C course — makes the early lessons quicker.

Practice

  • Playground — a starter program to copy and experiment with.
  • Exercises — fill-in-the-blank tasks and programming challenges with solutions.
  • Quiz — test your understanding across the whole course.
  • Syllabus & Study Plan — learning outcomes and a week-by-week schedule.

Lessons

Getting Started

  1. Introduction to C++
  2. Setting Up a C++ Compiler
  3. Your First Program

Basics

  1. Variables and Types
  2. Constants and constexpr
  3. Operators
  4. Input and Output with Streams
  5. Strings
  6. Type Conversions
  7. Conditions: if and switch
  8. Loops

Functions

  1. Functions
  2. References
  3. Passing Arguments: Value, Reference and Move
  4. Overloading and Default Arguments
  5. Scope, Lifetime and Namespaces

Containers

  1. Arrays and std::array
  2. Vectors
  3. string_view and span
  4. Structs and Enumerations
  5. Maps and Sets
  6. Stacks, Queues and Other Containers
  7. Iterators

Algorithms & Lambdas

  1. Lambda Expressions
  2. The Standard Algorithms
  3. Ranges and Views

Memory & Resources

  1. Pointers
  2. Dynamic Memory: new and delete
  3. Smart Pointers
  4. RAII: Resources That Clean Up After Themselves

Object-Oriented Programming

  1. Classes and Objects
  2. Constructors and Destructors
  3. Static Members and Friends
  4. Operator Overloading
  5. Copying and Moving Objects
  6. Inheritance
  7. Virtual Functions and Polymorphism
  8. Abstract Classes and Interfaces

Templates

  1. Function Templates
  2. Class Templates
  3. Concepts

Errors & the Standard Library

  1. Exceptions
  2. optional, variant and expected
  3. Files and Streams
  4. Formatting Text with std::format
  5. Random Numbers, Dates and Times
  6. Threads and Concurrency

Projects & Modern C++

  1. Headers and Multiple Source Files
  2. Building with CMake
  3. What's New in C++23
  4. Undefined Behaviour and Memory Safety
  5. Debugging, Testing and Best Practices
  6. Project: A Library Catalogue

Practice

  1. C++ Playground
  2. C++ Exercises
  3. C++ Quiz
  4. Syllabus & Study Plan
Where to start: begin with Introduction and set up a compiler in lesson 2 so you can run every example yourself. Afterwards, compare C++'s approach to safety with Rust, or keep your projects under version control with Git.