Smart pointers — automatic memory management.
1#include <memory>23// unique_ptr — exclusive4auto uptr = std::make_unique<int>(10);56// shared_ptr — shared7auto sptr1 = std::make_shared<int>(20);8auto sptr2 = sptr1; // ref count +1910// weak_ptr — non-owning11std::weak_ptr<int> wptr = sptr1;
unique_ptr — exclusive ownership.shared_ptr — reference counting.weak_ptr — breaks cycles.