shared_ptr std::shared_ptr<int> sp1 = new int(); // shared count = 1, weak count = 0 std::shared_ptr<int> sp2(sp1); // shared count = 2, weak count = 0 std::shared_ptr<int&...
这是C++11新特性介绍的第五部分,涉及到智能指针的相关内容(shared_ptr, unique_ptr, weak_ptr)。 shared_ptr shared_ptr 基本用法 shared_ptr采用引用计数的方式管理所指向的对象。当有一个新的shared_ptr指向...
如题,我们今天要讲的是C++11引入的三种智能指针中的最后一个:weak_ptr。在学习weak_ptr之前最好对shared_ptr有所了解。如果你还不知道shared_ptr是何物,可以看看我的另一篇文章【C++11新特性】 C++11智能指针...
目录 前言 weak_ptr这个指针天生一副“小弟”的模样,也是在c++11的时候引入的标准库,它的出现完全是为了弥补它老大shared_ptr天生有缺陷的问题,其实相比于上一代的智能指针auto_ptr来说,新进老大shared...