s******y 发帖数: 68 | 1 所有种类的smart pointer 都不可以做STL的参数?
还是只是smart pointer里的几种 不可以做STL的参数?
能说一下并给一些解释吗
谢谢 |
c*****e 发帖数: 11 | 2 boost的智能指针可以:)
而且很好用
stl的智能指针不能
【在 s******y 的大作中提到】 : 所有种类的smart pointer 都不可以做STL的参数? : 还是只是smart pointer里的几种 不可以做STL的参数? : 能说一下并给一些解释吗 : 谢谢
|
s*******e 发帖数: 28 | 3 auto_ptr in the Standard library doesn't have the normal copy behavior
because of the feature of transfer of ownership. Thus it can't be used
in the containers in STL which require normal copy function.
However, shared_ptr in TR1 or Boost is one smart pointer that uses reference
count and has normal behavior of copying. It can be used for STL. |
y*h 发帖数: 107 | 4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
解释解释这句吧, 没看懂.
Thus it can't be used
reference
【在 s*******e 的大作中提到】 : auto_ptr in the Standard library doesn't have the normal copy behavior : because of the feature of transfer of ownership. Thus it can't be used : in the containers in STL which require normal copy function. : However, shared_ptr in TR1 or Boost is one smart pointer that uses reference : count and has normal behavior of copying. It can be used for STL.
|
s*******e 发帖数: 28 | 5 std::auto_ptr sample1 = new T();
// sample1 points to or owns the resource allocated by new.
std::auto_ptr sample2 = sample1;
// While you copy or assign an auto_ptr, the resource that is owned by
sample1 early is now transfered to sample2. And sample1 = NULL.
//It is unlike the normal copy process where sample1 and sample2 both should
point to and share the resource. |