Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;共享\u ptr-附加到新的原始指针?_C++_Boost_Pointers_Shared Ptr - Fatal编程技术网

C++ C++;共享\u ptr-附加到新的原始指针?

C++ C++;共享\u ptr-附加到新的原始指针?,c++,boost,pointers,shared-ptr,C++,Boost,Pointers,Shared Ptr,我想我错过了一些简单的东西。我正在使用Boost的共享\u ptr shared_ptr<Foo> pA(new Foo()); shared_ptr<Foo> pB(new Foo()); shared_ptr pA(new Foo()); 共享_ptr pB(新Foo()); 现在,我想切换pB,使其包含pA的内容,从而减少pB的引用计数。我如何才能做到这一点?这一切都是自动完成的: pB = pA; // pB ref count is decrement

我想我错过了一些简单的东西。我正在使用Boost的
共享\u ptr

shared_ptr<Foo> pA(new Foo()); 
shared_ptr<Foo> pB(new Foo()); 
shared_ptr pA(new Foo());
共享_ptr pB(新Foo());

现在,我想切换
pB
,使其包含
pA
的内容,从而减少
pB
的引用计数。我如何才能做到这一点?

这一切都是自动完成的:

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.

“Boost的std::tr1::shared_ptr”有点奇怪,你不觉得吗?:)Boost已经<代码> Boo::StRADYPPTR:/ToC:<代码> STD::SyrdYPPTR ,C++ +0x有代码> STD::SyrdYPPTR 。Boost还包含一个Tr1库,其中包含SyrdY-PTR,它解析STD::Tr1::SydDypTR到C++的本地LID::SydDypTR,或者如果不存在这样的Booo::SyrdYPPTR。因此,boost的std::tr1::shared_ptr是有效且有意义的。