If we make them smarter they will become self-aware



Smart pointers

Smart pointers are objects that store pointers to dynamically allocated objects. The purpose of them is to manage to lifetime of the object being pointed to. The smart pointer owns the object it points to and to access the object you must use the smart pointer. When the smart pointer goes out of scope it checks that no one us still using the object it points to and if so it deletes it.

std::unique_ptr - C++11 - For exclusive-ownership of a resource


std::shared_ptr - C++11 - For shared-ownership of a resource


std::weak_ptr - C++11

A weak_ptr holds a reference to an object managed by a shared_ptr, but does not contribute to the reference count. To access the object one use the lock() function on the weak_ptr to create a shared_ptr.

std::auto_ptr - C++98, deprecated since C++11

This was the first try of making a smart pointer object in C++. Deprecated in C++11 when the better working ways above was created.