Posted on 2011-03-23 10:01
Tommy Liang 阅读(237)
评论(0) 编辑 收藏 引用 所属分类:
C++语言与规范
Use scoped_ptr when
-
A pointer is used in a scope where an exception may be thrown
-
There are several control paths in a function
-
The lifetime of a dynamically allocated object can be limited to a specific scope
-
Exception safety is important (always!)
Use shared_ptr in the following scenarios:
When there are multiple clients of an object, but no explicit owner
-
When storing pointers in Standard Library containers
-
When passing objects to and from libraries without (other) expressed ownership
-
When managing resources that need special cleanup
Use weak_ptr to
check:http://my.oschina.net/jackwgm/blog/6695?catalog=23886