avatar
s*y
1
所有种类的smart pointer 都不可以做STL的参数?
还是只是smart pointer里的几种 不可以做STL的参数?
能说一下并给一些解释吗
谢谢
avatar
c*e
2
boost的智能指针可以:)
而且很好用
stl的智能指针不能

【在 s******y 的大作中提到】
: 所有种类的smart pointer 都不可以做STL的参数?
: 还是只是smart pointer里的几种 不可以做STL的参数?
: 能说一下并给一些解释吗
: 谢谢

avatar
s*e
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.
avatar
y*h
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.

avatar
s*e
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.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。