YouTube

Session 24 of Software Lessons, “Smart Pointers, Virtual Classes, Abstract Classes, Concrete Classes,” runs about 24 minutes.

What this session covers

  • Smart pointers
    • Unique pointer (exclusive ownership of the memory)
    • Shared pointer (shared ownership of the memory)
    • Weak pointer (a non-owning observer that does not extend the life of the memory and has no formal ownership)
  • Object-oriented programming: abstraction, encapsulation, polymorphism, inheritance
    • Virtual classes
    • Abstract classes
    • Concrete classes

Key ideas

  • A smart pointer is an object that owns a heap allocation and releases it automatically, which avoids manual delete calls and leaks.
  • A unique pointer has exactly one owner and cannot be copied, only moved.
  • A shared pointer keeps a count of owners and frees the memory when the last owner goes away.
  • A weak pointer observes memory managed by a shared pointer without keeping it alive.
  • An abstract class declares an interface with at least one pure virtual function and cannot be instantiated, while a concrete class implements everything and can be.