Free course · 11 lessons · Beginner

Modern C++ Fundamentals: From Basics to Smart Pointers and Threads

Learn modern C++20 from your first program to safe, fast code: building and formatting, values and references with const correctness, strings, vectors and maps, lambdas and standard algorithms, classes and RAII, inheritance and polymorphism, smart pointers and ownership, move semantics, templates and concepts, exceptions, optional, variant and ranges, and threads with a parallel word counter capstone. Every example is compiled with g++ in C++20 mode and shown with its real output.

Start the course

1. Modern C++ Basics: Types, Containers, Functions and Classes

Start with modern C++20 (not old C-with-classes): values and references, std::string and std::vector, functions and lambdas, and classes that clean up after themselves.

  1. Hello, C++: Building, Types and Formatting — Compile and run a C++ program, use the core types with auto and const, read the standard library's std::format, and learn the habits that keep modern C++ safe.
  2. Values, References, Pointers and const Correctness — Understand how C++ passes values, use references to avoid copies, apply const correctness, and know when a pointer is the right tool.
  3. Strings, Vectors and Maps: The Everyday Containers — Use std::string, std::vector and std::unordered_map, loop with range-based for and structured bindings, and find, count and group data without manual memory management.
  4. Functions, Lambdas and the Standard Algorithms — Overload functions, use default arguments, write lambdas with captures, and replace hand-written loops with std::sort, std::find_if, std::transform and std::accumulate.
  5. Classes and RAII: Objects That Clean Up After Themselves — Write classes with constructors, member functions and encapsulation, and learn RAII, the C++ idea that ties resources to object lifetime so cleanup is automatic.
  6. Inheritance and Polymorphism — Define a base class with virtual functions, override them in derived classes, store different shapes behind one interface using smart pointers, and avoid slicing.

2. Ownership, Templates, Errors and Concurrency

The ideas that make C++ powerful: smart pointers and ownership, move semantics, templates and concepts, safe error handling and ranges, and threads.

  1. Smart Pointers and Ownership — Replace raw new and delete with std::unique_ptr and std::shared_ptr, break reference cycles with std::weak_ptr, and learn the ownership rules that prevent leaks.
  2. Move Semantics and the Rule of Five — Understand lvalues and rvalues, use std::move to transfer resources instead of copying them, and write move constructors that make large objects cheap to pass around.
  3. Templates and Concepts — Write function and class templates, constrain them with C++20 concepts and requires clauses, and read the clear error messages that constraints give you.
  4. Errors, optional, variant and Ranges — Handle errors with exceptions and noexcept, represent absent values with std::optional, model alternatives with std::variant and std::visit, and process data lazily with C++20 ranges.
  5. Capstone: A Parallel Word Counter with Threads — Run work on several threads with std::jthread, protect shared data with std::mutex and lock_guard, collect results with std::async, and combine everything in a parallel word counter.

Was this page helpful?