C++ smart pointers and RAII: unique_ptr, shared_ptr, weak_ptr

8 steps · about 4 h · Intermediate

  1. Smart pointers (Modern C++) (article, Microsoft Learn, 15 min)

    Starts with the problem: a raw new/delete pair versus a smart pointer that cleans up on its own.

  2. 20. Smart Pointers — Programming for Financial Technology (article, Duke University, 25 min)

    A short course chapter with runnable examples of all three pointer types and best practices.

  3. Smart Pointers — cppcheatsheet (article, cppcheatsheet, 15 min)

    A compact reference to make_unique, make_shared, moving ownership and custom deleters, to type out yourself.

  4. std::unique_ptr - cppreference.com (reference, cppreference, 25 min)

    The precise rules for moving, custom deleters, arrays and derived-to-base conversion, with a worked example.

  5. Smart Pointers in C++ - unique_ptr, shared_ptr, weak_ptr and Ownership Explained (article, CompilersUtra, 15 min)

    Frames smart pointers as a way to model ownership, which sets up choosing between them.

  6. C++ Core Guidelines: Rules about Resource Management (blog, modernescpp.com, 15 min)

    Explains who owns what: scoped objects, references, raw pointers and unique_ptr.

  7. C++ Core Guidelines (doc, isocpp.org, 40 min)

    The official rules R.20 to R.30 cover unique_ptr over shared_ptr, make_shared, weak_ptr for cycles and smart pointer parameters.

  8. CppCon 2014 Back to the Basics! Essentials of Modern C++ Style--Herb Sutter (video, Standard C++ / Herb Sutter, 1 h 30 min)

    Herb Sutter, a longtime ISO C++ committee chair, ends the list with how smart pointers fit into everyday modern C++ style.