Smart Pointers: Shared Pointers
Next, we will go over shared pointers, which follow the principle of keeping a reference count to maintaining the count of its copies. The lesson below elaborates further.
We'll cover the following...
Introduction
std::shared_ptr shares the ownership of the resource. They have two handles: one for the resource and one for the reference counter. By copying a std::shared_ptr
, the reference count is increased by one. It is decreased by one if the std::shared_ptr
goes out of scope. If the reference counter becomes the value 0, the C++ runtime automatically releases the resource, since there is no std::shared_ptr
referencing the ...