Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Modern C++ (C++11+) wrappers around raw pointers that automatically manage memory. They call delete for you when the pointer is no longer needed.
unique_ptrExclusive ownership. Cannot be copied, only moved.
shared_ptrShared ownership. Uses reference counting.
weak_ptrPoints to shared_ptr but doesn't increase ref count.
#include <memory> auto ptr = make_unique<MyClass>(); // Memory freed automatically when ptr goes out of scope!
In modern C++, you should ALMOST NEVER use raw new and delete. Smart pointers eliminate whole categories of memory leaks and bugs.