你能解释什么是智能指针的类型,它们如何工作以及何时使用它们?@H_301_3@
此外,在其他人写的接口中接收或传递原始指针时,“协议”是什么?@H_301_3@
谢谢.@H_301_3@
解决方法
Can you explain what are the types of smart pointers,how do they work and when to use them?@H_301_3@
有一些他们.简而言之:@H_301_3@
scoped_ptr
<boost/scoped_ptr.hpp>
Simple sole ownership of single
objects. Noncopyable.@H_301_3@
scoped_array
<boost/scoped_array.hpp>
Simple sole
ownership of arrays. Noncopyable.@H_301_3@
shared_ptr
<boost/shared_ptr.hpp>
Object ownership shared among
multiple pointers. @H_301_3@
shared_array
<boost/shared_array.hpp>
Array
ownership shared among multiple
pointers. @H_301_3@
weak_ptr
<boost/weak_ptr.hpp>
Non-owning
observers of an object owned by
shared_ptr. @H_301_3@
intrusive_ptr
<boost/intrusive_ptr.hpp>
Shared
ownership of objects with an embedded
reference count.@H_301_3@
(这是从Boost文档,并注意到它们也有这样的指针的容器!)@H_301_3@
Also,what is the “protocol” when receiving or passing raw pointers in interfaces written by other people?@H_301_3@
对我而言,最重要的规则是:@H_301_3@
>宪章资格>不要释放我没有分配的东西检查所有权/移动语义的转移@H_301_3@