thecodex.expert · The Codex Family of Knowledge
Track 1 — Foundations

C++: Foundations

Five lessons: core syntax, classes, RAII, and the smart pointers that make manual memory management obsolete.

🕐 ~5 hours5 lessonsModern C++20

Lessons

Lesson 1

Variables, types, and control flow

int, double, bool, char, string; if/else; for, while; switch; std::cin and std::cout; namespaces.

What to look for:

  • C++ is statically typed — every variable has a fixed type at compile time
  • int (32-bit signed), double (64-bit float), std::string (heap-managed text)
  • std::cout << value << "\n" — not printf (C-style)
  • using namespace std; — convenient but can cause name collisions in large projects
🕑 50 min
Lesson 2

Functions, references, and const

Function overloading, pass by value vs reference (&), const correctness, default arguments, and inline functions.

Prerequisite: Lesson 1

What to look for:

  • Pass by reference (&) avoids copying large objects; const & reads without modifying
  • const T& parameter: "I promise not to modify this" — enforced by compiler
  • Overloading: multiple functions with the same name, different parameter types
  • References are aliases — not pointers; they cannot be null; they cannot be reseated
🕑 50 min
Lesson 3

Classes, constructors, and destructors

Class definition, public/private/protected, member initialiser lists, explicit constructors, and the destructor.

Prerequisite: Lesson 2

What to look for:

  • Member initialiser list: MyClass(int x) : member(x) {} — initialises, not assigns
  • explicit constructor prevents implicit conversion: explicit Buffer(int size)
  • The destructor (~ClassName) always runs when the object goes out of scope
  • const member functions (void show() const): cannot modify member variables
🕑 55 min
Lesson 4

RAII: resource management in C++

RAII pattern, exception safety, why raw new/delete are error-prone, and how destructors make cleanup automatic.

Prerequisite: Lesson 3

What to look for:

  • The destructor is where RAII happens — it always runs, exception or not
  • Acquire in constructor, release in destructor: file open/close, lock/unlock, connect/disconnect
  • Three exception safety levels: basic (no leak), strong (commit-or-rollback), nothrow
  • noexcept: promise to never throw — move constructors should be noexcept
🕑 50 min
Lesson 5

Smart pointers: unique_ptr and shared_ptr

make_unique, make_shared, ownership semantics, moving unique_ptr, shared_ptr ref counting, weak_ptr, and when to use which.

Prerequisite: Lesson 4

What to look for:

  • unique_ptr: sole ownership, zero overhead — prefer for most cases
  • shared_ptr: shared ownership, atomic refcount overhead — use when truly needed
  • weak_ptr: observe a shared_ptr without owning — breaks circular reference cycles
  • Never pass smart pointers to functions unless ownership is being transferred — pass raw pointer or reference
🕑 50 min

How to use this track: Each lesson links to the C++ reference pages. Practice at godbolt.org — paste code and see the compiler output live. Pay attention to compiler warnings (-Wall -Wextra): C++ warns about many common mistakes.

Track quiz

4 questions to check your understanding.

When is a C++ object's destructor called?

What does passing by const reference (const T&) do?

What is RAII?

Can you copy a std::unique_ptr?

Practitioner track →