```cpp #include #include #include //智能指针总结: /* */ void sharedPtrNotice(); class Parent; typedef std::shared_ptr ParentPtr; typedef std::weak_ptr WeakP... ...
分类:
编程语言 时间:
2020-02-24 20:10:34
阅读次数:
106
shared_ptr是一个最像指针的“智能指针”,是boost.smart_ptr库中最有价值、最重要的组成部分,也是最有用的,Boost库的许多组件——甚至还包括其他一些领域的智能指针都使用了shared_ptr,所以它被毫无悬念地收入了C++11标准。 shared_ptr与scoped_ptr ...
分类:
其他好文 时间:
2019-08-20 21:50:45
阅读次数:
86
+ 错误信息 /usr/include/boost/smart_ptr/shared_ptr.hpp:646: typename boost::detail::sp_dereference::type boost::shared_ptr::operator () const [with T = pc ...
分类:
其他好文 时间:
2018-12-06 20:50:18
阅读次数:
660
c++11标准和boost都提供了智能指针的功能。智能指针是普通指针的封装,智能指针是一个对象,对象里面包含了原生指针。可以使用智能指针对象的get()方法可获得封装在里面的原生指针。使用智能指针管理内存,用到智能指针的地方需要统一使用c++11或boost库,切忌混合使用。c++11的智能指针包含 ...
分类:
其他好文 时间:
2018-10-30 14:48:03
阅读次数:
123
#include #include using namespace std; template class smart{ private: T* _ptr; int* _count; //reference counting public: //构造函数 smart(T* ptr = nullptr... ...
分类:
编程语言 时间:
2018-10-04 08:51:04
阅读次数:
174
1、共享性智能指针(shared_ptr)引用计数型指针shared_ptr是一个最像指针的“智能指针”,是boost.smart_ptr库中最有价值,最重要,也是最有用的。shared_ptr实现的是引用技术型的智能指针,可以被拷贝和赋值,在任意地方共享它,当没有代码使用(此时引用计数为0)它才删除被动态..
分类:
其他好文 时间:
2016-07-30 22:48:26
阅读次数:
300
在C语言中我们用指针来进行内存管理,这也是C语言的强大之处。然而,也正是指针的存在使得C语言变得令人懊恼,内存泄漏、垂悬指针等等问题。强大的C++则采用智能指针(Smart_Ptr)来处理这个问题.好了,什么是智能指针呢?智能指针的行为类似常规指针,重要的区别是它负责自动释..
分类:
其他好文 时间:
2016-04-10 01:25:47
阅读次数:
230
smart_ptr
raii ( Resource Acquisition Is Initialization )
智能指针系列的都统称为smart_ptr,包括c++98标准的auto_ptr
智能指针是一个类,通过重载->和*完成类似原始指针的操作。不过因为是类,所以可以做比如内存管理、线程安全之类的工作
智能指针均是自动管理内存,不需要显示调用delete
scoped_ptr...
分类:
其他好文 时间:
2016-03-26 07:59:56
阅读次数:
210
实例用法: 创建对象: class U_Ptr smart; U_Ptr* ptr = new U_Ptr(); class U_Ptr smart(new U_Ptr(p)); int *p = new int; //此时指针p指向一个int对象,该对象没有被初始化 int...
分类:
编程语言 时间:
2015-12-23 12:22:33
阅读次数:
306
just read it
smart_ptr: https://mbevin.wordpress.com/2012/11/18/smart-pointers/
move: https://mbevin.wordpress.com/2012/11/20/move-semantics/...
分类:
编程语言 时间:
2015-06-26 13:03:36
阅读次数:
237