A guide to C++: From Basics to Expert

How to work through this course

Three phases, roughly a hundred to a hundred and forty hours. C++ is a large language and nobody knows all of it - not the people on the standards committee, who say so freely. The goal is not coverage. It is to know the parts that hold a real program together well enough that the rest is lookup.

Turn the warnings on before you write the first file.

g++ -std=c++20 -Wall -Wextra -Wpedantic -g main.cpp -o main

C++ inherited C's permissive defaults, and the single biggest difference between learning this language well and badly is whether you read what those flags report or scroll past them. From phase two, when pointers and the heap arrive, add the sanitisers:

g++ -std=c++20 -Wall -Wextra -g -fsanitize=address,undefined main.cpp -o main

The address sanitiser catches use-after-free, buffer overruns and leaks, and tells you the line that allocated the memory as well as the line that misused it. It costs about two times the runtime, which during study is free. On MSVC the equivalents are /W4 and /fsanitize=address.

Phase 1, around thirty hours. The language as a procedural one. If you already know C, this is mostly familiar and you should still read the parts on brace initialization, std::string and references, because each of those is C++ answering a C problem and the answers reappear everywhere later.

Build: a command-line tool that reads numbers from a text file and reports some statistics on them. No classes. The point is to get comfortable with the compile-run-fix loop and to meet std::vector and std::string before anything is asked of you.

Phase 2, around fifty hours, and the one that decides things. The stack and the heap, pointers and references, classes, the STL, files and exceptions.

Do not rush the memory topic. Everything in phase 3 - move semantics, smart pointers, RAII - is a solution to a problem that first phase shows you. Smart pointers will feel like syntax to memorise if you have not first leaked memory yourself, and like an obvious relief if you have. Allocate with new, forget a delete, and watch the sanitiser tell you about it. Then do it properly.

Build: an inventory or contact manager. A base class and two derived ones, a std::vector of base pointers iterated polymorphically, saving to and loading from a file, and exceptions where the file is malformed. Write it with new and delete, deliberately, and keep that version - you will rewrite it in phase 3 and the diff is the lesson.

Phase 3, around forty hours. Modern C++, from C++11 to C++23.

Start by rewriting the phase 2 project with std::unique_ptr and std::make_unique. The deletes disappear, the destructors shrink, and the code gets shorter. That rewrite teaches move semantics better than reading about rvalue references does, because you can see what the compiler stopped copying.

Templates and concepts repay slow reading. The first template error message you get will be hundreds of lines; learn to read it from the bottom up, where the actual cause usually sits, and then learn to prevent it with a concept. Concurrency is the topic to be most careful with: write the data race on purpose, run it with -fsanitize=thread, and see the tool name both threads and both lines. A race you have watched the sanitiser catch is a race you will recognise again.

Build: a thread-pooled file processor. Walk a directory, hand each file to one of N worker threads, and collect the results. It exercises std::jthread or std::async, a mutex around the shared results, RAII for the files, and a CMake build with tests.

What to skip on a first pass. You can leave these for later without being held back: the gnarlier corners of template metaprogramming (SFINAE, tag dispatch - concepts have largely replaced the need), custom allocators, volatile, multiple inheritance and virtual bases, and the relaxed memory orderings on atomics. std::memory_order_seq_cst is the default and is correct; the weaker orderings are a performance optimisation that experts get wrong.

Where to check things. cppreference.com is the reference - dense, exact, and worth the adjustment period. The C++ Core Guidelines, edited by Stroustrup and Sutter, answer "what should I actually do here" better than any tutorial. Compiler Explorer shows you the assembly your code compiles to, side by side, and is the fastest way to settle an argument about whether an abstraction really is zero-cost.

One habit worth forming now. When you learn a new feature, put it in Compiler Explorer with optimisations on and look at what it becomes. A range-based for over a vector compiles to the same loop as the index version. A unique_ptr compiles to a pointer and a delete. Seeing that is what turns "C++ is fast" from something you have been told into something you know.

oop (Object-Oriented Programming) pointers-and-references memory-management data-structures algorithms templates generic-programming stl (Standard Template Library) concurrency multithreading