Unique_ptr
A unique_ptr is a smart pointer in C++ that manages the lifetime of a dynamically allocated object. It ensures that the object is automatically deleted when the unique_ptr goes out of scope, preventing memory leaks. Unlike regular pointers, a unique_ptr cannot be copied, which means that it maintains sole ownership of the object it points to.
This ownership model allows for safer memory management in C++ programs. You can transfer ownership of the managed object using the std::move function, which makes it possible to pass the unique_ptr between functions without risking multiple pointers to the same object.