摘要: Defined in headertemplateclassshared_ptr;(since C++11)std::shared_ptris a smart pointer that retains shared ownership of an object through a pointer. Severalshared_ptrobjects may own the same object; the object is destroyed when the last remainingshared_ptrpointing to it is destroyed or reset. The o 阅读全文
posted @ 2014-03-08 15:45 zzyoucan 阅读(460) 评论(0) 推荐(0) 编辑
摘要: auto_ptr是C++标准库中()为了解决资源泄漏的问题提供的一个智能指针类模板(注意:这只是一种简单的智能指针)auto_ptr的实现原理其实就是RAII,在构造的时候获取资源,在析构的时候释放资源,并进行相关指针操作的重载,使用起来就像普通的指针。std::auto_ptr pa(new ClassA);下面主要分析一下auto_ptr的几个要注意的地方:1,Transfer of Ownershipauto_ptr与boost库中的share_ptr不同的,auto_ptr没有考虑引用计数,因此一个对象只能由一个auto_ptr所拥有,在给其他auto_ptr赋值的时候,会转移这种拥有 阅读全文
posted @ 2014-03-08 13:18 zzyoucan 阅读(340) 评论(0) 推荐(0) 编辑