1.auto_ptr

这个所谓的只能指针有点鸡肋!  没有引用计数,而且还有一个所有权转移的情况!

当所有权转移后,以前的auto_ptr将会成为null

2.shared_ptr

增加了引用计数,没有所有权转移问题

但是它俩在析构的时候都没有delete[]动作,所以不能释放数组类型!

当然,可以重写一个可以释放数组的模板类!

C++ 之 auto_ptr and shared_ptr的更多相关文章

  1. 初次窥见智能指针auto_ptr和shared_ptr

    #include <memory>//shared_ptr要用的头文件 using namespace std; class A //测试auto_ptr和shared_ptr的delet ...

  2. stl中auto_ptr,unique_ptr,shared_ptr,weak_ptr四种智能指针使用总结

    stl中auto_ptr,unique_ptr,shared_ptr,weak_ptr四种智能指针使用总结 1. auto_ptrauto_ptr主要是用来解决资源自动释放的问题,比如如下代码:voi ...

  3. auto_ptr与shared_ptr ZZ

    http://blog.csdn.net/rogeryi/article/details/1442700 Part(1) 这篇文章试图说明如何使用auto_ptr和shared_ptr,从而使得动态分 ...

  4. auto_ptr, unique_ptr, shared_ptr and weak_ptr智能指针讲解

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  5. auto_ptr和shared_ptr

    <Effective C++>在资源管理一节提到了智能指针,智能指针中最著名的当属auto_ptr和shared_ptr.本文主要研究两者的实现. auto_ptr的实现: templat ...

  6. C++ 智能指针 auto_ptr 和 shared_ptr

    首先,如果你不知道什么是智能指针,请先移步:C++智能指针简单剖析 1.auto_ptr #ifndef AUTO_PTR_H #define AUTO_PTR_H template<typen ...

  7. C++智能指针 auto_ptr、shared_ptr、weak_ptr和unique_ptr

    手写代码是理解C++的最好办法,以几个例子说明C++四个智能指针的用法,转载请注明出处. 一.auto_ptr auto_ptr这是C++98标准下的智能指针,现在常常已经被C++标准的其他智能指针取 ...

  8. 关于std:auto_ptr std:shared_ptr std:unique_ptr

    很多人听说过标准auto_ptr智能指针机制,但并不是每个人都天天使用它.这真是个遗憾,因为auto_ptr优雅地解决了C++设计和编码中常见的问题,正确地使用它可以生成健壮的代码.本文阐述了如何正确 ...

  9. <memory>(包括了auto_ptr,shared_ptr等各种指针)

    Memory elements This header defines general utilities to manage dynamic memory: Allocators allocator ...

随机推荐

  1. mysql order by in 的字符顺序

    //MySQL 语句SELECT * FROM `MyTable`WHERE `id` IN (11,1,111) ORDER BY FIELD(`id`, 11,1,111); laravel 框架 ...

  2. arm cache line,PLD指令

    C中嵌入汇编PLD指令:asm("PLD [%0,#128]": :"r" (psrc) ); copy自官方文档: 4.2.7. PLD.PLDW 和 PLI ...

  3. Php中的强制转换详解

    强制转换中分为两种,第一种就只临时转换,和永久转换.在临时转换中呢,首先可以通过第一中方式来显示,就是小括号的形式,临时转换成整型我们可以通过(int)都是这样的形式,或者是(integer)临时转换 ...

  4. matplotlib总结

    主要使用matplot.pyplot import matplot.pyplot as plt plt.figure(1) plt.subplot(211) plt.plot(x,y, 'rs') p ...

  5. class命名

    常见class关键词: 布局类:header, footer, container, main, content, aside, page, section 包裹类:wrap, inner 区块类:r ...

  6. [HTML/CSS] ul元素居中处理

    CSS: <style type="text/css"> #nav_sub_page { text-align: center; width: 80%; } #nav_ ...

  7. .frm,.myd,myi转换为.sql导入数据库

    先说说这几种文件是干什么的: *.frm是描述了表的结构, *.myd保存了表的数据记录, *.myi则是表的索引. 其实一个.frm文件就是对应的数据库中的一个表,表示数据表的表结构. .MYD文件 ...

  8. CSS轮廓outline

    http://www.cnblogs.com/xiaohuochai/p/5277416.html

  9. C++语法-指针 (1)

    <C++程序设计> 谭浩强  清华大学出版社 2016-08-03 1.P167 一般的C++编译系统为每个指针变量分配4个字节的存储单元,用来存放变量的地址. 2.P169 .cpp文件 ...

  10. sphinx索引分析续

    4.10 同义词文件/Synonym 同义词文件格式 from => to AT &T => AT&T AT & T => AT & T standa ...