Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Coursera

Practical Guide to Mastering C++ Smart Pointers - Part 02

Packt via Coursera

Overview

Google, IBM & Meta Certificates — All 10,000+ Courses at 40% Off
One annual plan covers every course and certificate on Coursera. 40% off for a limited time.
Get Full Access
This course features Coursera Coach! A smarter way to learn with interactive, real-time conversations that help you test your knowledge, challenge assumptions, and deepen your understanding as you progress through the course. Memory management is one of the most critical aspects of modern C++ development, and smart pointers are essential tools for writing safe, efficient, and maintainable code. In this course, you will gain a deep understanding of C++ smart pointers, with a strong focus on std::shared_ptr, std::weak_ptr, and std::make_shared. Through practical explanations and real-world examples, you will learn how smart pointers simplify memory management, prevent common errors like memory leaks and dangling pointers, and help you design robust applications. You will begin by exploring the fundamentals of std::shared_ptr, including reference counting, copy semantics, and how shared ownership works in modern C++. The course then demonstrates how to replace traditional raw pointers with smart pointers to eliminate common resource management issues. Through detailed examples, you will also see how smart pointers interact with containers, polymorphism, and multithreading. As the course progresses, you will dive into advanced practical usage such as custom deleters, control blocks, and managing complex resources like file handles, DLL handles, POSIX file descriptors, and Win32 resources. You will also learn how smart pointers behave across DLL boundaries and how std::make_shared optimizes object creation and memory allocation. This course is designed for C++ developers who want to strengthen their understanding of modern C++ memory management techniques. Developers with basic knowledge of C++ programming, pointers, and object-oriented programming will benefit most. The course is suitable for intermediate learners aiming to write safer and more professional C++ code. By the end of the course, you will be able to confidently implement std::shared_ptr, std::weak_ptr, and std::make_shared, manage complex system resources safely, prevent cyclic dependencies, and design efficient memory management strategies in modern C++ applications.

Syllabus

  • Course Introduction
    • In this module, we will introduce the course and outline the learning journey for mastering C++ smart pointers. You will gain an overview of the concepts and practical topics that will be explored throughout the course. This section prepares you for deeper learning by explaining the objectives and real-world relevance of smart pointers.
  • std::shared_ptr Fundamentals
    • In this module, we will explore the fundamental concepts of std::shared_ptr and its role in modern C++ programming. You will learn how shared ownership works through reference counting and practical coding examples. The section also covers how std::shared_ptr behaves when copied, returned from functions, or passed as arguments.
  • Replacing Raw Pointers With shared_ptr
    • In this module, we will examine the problems associated with raw pointers and how std::shared_ptr provides safer alternatives. You will learn how to prevent memory leaks, dangling pointers, and uninitialized pointer issues. The section also demonstrates real-world usage in containers, polymorphism, and multithreaded applications.
  • Practical Usage
    • In this module, we will dive into practical applications of std::shared_ptr for real-world resource management. You will explore control blocks, custom deleters, and advanced memory management mechanisms. The section also demonstrates how to safely manage system resources like file handles, DLLs, and OS-level objects.
  • Deleter Internals
    • In this module, we will explore the internal workings of custom deleters and how they integrate with std::shared_ptr. You will learn how smart pointers behave across DLL boundaries and different runtime environments. This section also explains advanced scenarios involving C runtime libraries and cross-module resource management.
  • std::make_shared
    • In this module, we will explore the efficient construction of shared pointers using std::make_shared. You will learn how it improves memory allocation and simplifies object creation compared to traditional methods. The section also examines control block layout and memory optimization techniques.
  • std::weak_ptr
    • In this module, we will explore the role of std::weak_ptr in managing shared resources without owning them. You will learn how weak pointers help avoid cyclic dependencies and enable temporary access to shared objects. The section also demonstrates advanced patterns combining std::shared_ptr, std::weak_ptr, and std::make_shared for robust memory management.

Taught by

Packt - Course Instructors

Reviews

Start your review of Practical Guide to Mastering C++ Smart Pointers - Part 02

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.