现在的位置: 首页 > 综合 > 正文

Boost和STL的几种智能指针

2018年02月16日 ⁄ 综合 ⁄ 共 3072字 ⁄ 字号 评论关闭

1.scoped_ptr

scoped_ptr has similar
characteristics to std::auto_ptr, with the important difference that it doesn't transfer ownership
the way an auto_ptr does

.

 

 

2.shared_ptr

These smart pointers eliminate the need to write complicated logic to control the lifetime of objects shared among two or more other objects. When the reference count drops to zero
, no more objects are interested in the shared object, and so it is deleted automatically
.



The following example shows how to store shared pointers in a Standard Library container.

当shared_ptr对象销毁时,调用指定的函数对象

抱歉!评论已关闭.