标签:cti des sam ptr unique func reset memory point
0.
1. std::shared_ptr is a smart pointer that retains shared ownership of an object through a pointer. Several shared_ptr objects may own the same object. The object is destroyed and its memory deallocated when either of the following happens: (1) the last remaining shared_ptr owning the object is destroyed. (2) the ownership is transfed via operator= or reset()
2. Some examples, showing how to use member functions
#include <memory>
std::shared_ptr<int> foo;
std::shared_ptr<int> bar(new int);
std::cout << foo.unique(); // false;
foo = bar; // assignment
std::cout << foo.unique(); // false, shared with bar
std::cout << foo.use_count(); // 2
bar = nullptr;
std::cout << foo.unique(); // true
标签:cti des sam ptr unique func reset memory point
原文地址:https://www.cnblogs.com/sarah-zhang/p/12219851.html