[英]C++ shared_ptr - attach to a new raw pointer?
I think I'm missing something simple here. 我想我在这里缺少一些简单的东西。 I'm using Boost's
shared_ptr
. 我正在使用Boost的
shared_ptr
。
shared_ptr<Foo> pA(new Foo());
shared_ptr<Foo> pB(new Foo());
Now, I want to switch pB
so it contains the contents of pA
, decrementing the ref count of pB
. 现在,我想切换
pB
,使其包含pA
的内容,减少pB
的引用计数。 How can I do this? 我怎样才能做到这一点?
It's all done automatically: 这一切都是自动完成的:
pB = pA; // pB ref count is decrement (in this case causing the value to be released)
// pB is then made to point at the same value as pA
// Thus incrementing the refCount.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.