constexpr shared_ptr() noexcept; constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() {} shared_ptr(const shared_ptr& sp) noexcept; shared_ptr(shared_ptr&& sp) noexcept; template <class Other> explicit shared_ptr(Other* ptr); template <class Other, class Deleter> shared_ptr( Other*...
constexpr shared_ptr() noexcept; constexpr shared_ptr(nullptr_t) noexcept : shared_ptr() {} shared_ptr(const shared_ptr& sp) noexcept; shared_ptr(shared_ptr&& sp) noexcept; template <class Other> explicit shared_ptr(Other* ptr); template <class Other, class Deleter> shared_ptr( Other*...
template<class Ty> class shared_ptr { public: typedef Ty element_type; shared_ptr(); shared_ptr(nullptr_t); shared_ptr(const shared_ptr& sp); shared_ptr(shared_ptr&& sp); template<class Other> explicit shared_ptr(Other * ptr); template<class Other, class D> shared_ptr(Other * ptr...
一、class shared_ptr。共享式拥有。多个shared_ptr可以指向同一个对象,该对象和起相关资源会在最后一个指针被销毁时释放。 二、class unique_ptr。独占式拥有。同一时间只有一个smart pointer可以指向该对象。对于避免资源泄露特别有用。 1.Class shared_ptr 1.1 使用shared_ptr 可以像使用其他指针一样使用shared_pt...
class F {}; class G : public F {}; shared_ptr<G> sp0(new G); // okay, template parameter G and argument G* shared_ptr<G> sp1(sp0); // okay, template parameter G and argument shared_ptr<G> shared_ptr<F> sp2(new G); // okay, G* convertible to F* shared_ptr<F> sp3(...
<class D> shared_ptr(nullptr_t, D dtor); template<class Other, class D, class A> shared_ptr(Other *ptr, D dtor, A alloc); template<class D, class A> shared_ptr(nullptr_t, D dtor, A alloc); template<class Other> shared_ptr(const shared_ptr<Other>& sp); template<class Other>...
class shared_ptr : public __shared_ptr<_Tp> { public: ... // 构造函数 template<typename _Tp1> explicit shared_ptr(_Tp1* __p) :__shared_ptr<_Tp>(__p) { } ... }; 由于源代码过长,这里就只贴出其中一部分进行分析: 该类没有类成员 ...
shared_ptr Class shared_ptr::~shared_ptr shared_ptr::element_type shared_ptr::get shared_ptr::operator boolean-type shared_ptr::operator* shared_ptr::operator= shared_ptr::operator-> shared_ptr::reset shared_ptr::shared_ptr shared_ptr::swap ...
2.1 class shared_ptr 提供了共享式拥有语义,也就是说当对个shared_ptr可以共享(或拥有)同一个对象,对象的最后一个拥有者有责任销毁对象,并清理与该对象相关的所有资源,也就是说它所指向的对象不再被需要时,自动释放(当超出作用域时,其析构函数被调用,在析构函数中,将其引用计数减1,如果引用计数的值变为0,...
The shared_ptr class describes an object that uses reference counting to manage resources. Ashared_ptrobject effectively holds a pointer to the resource that it owns or holds a null pointer. A resource can be owned by more than oneshared_ptrobject; when the lastshared_ptrobject that owns a...