C ++ std :: auto_ptr复制构造函数 [英] C++ std::auto_ptr copy constructor
问题描述
std :: auto_ptr缺少const复制构造函数,因此我不能直接在集合中使用它。有没有一些方法可以有例如std :: auto_ptr的向量而不使用增强指针集合模板?
std::auto_ptr lacks const copy constructor, therefore I cannot use it directly in collections. is there some way to have for example vector of std::auto_ptr without using boost pointer collection template?
推荐答案
C ++ 0x编译器,您可以根据需要使用 shared_ptr
或 unique_ptr
。
If you have a C++0x compiler you can use shared_ptr
or unique_ptr
as appropriate.
有正确的 unique_ptr
用法在这里感谢@James McNellis。对于 shared_ptr
演练,请此处,由@ D.Shawley提供。 [Upvote仍然会赞赏这些线程,我相信。]
There is a good example of correct unique_ptr
usage here courtesy of @James McNellis. For a shared_ptr
walkthrough look here, courtesy of @D.Shawley. [Upvotes would still be appreciated on those threads, I am sure.]
向量的
auto_ptr
总是无效,虽然Visual C ++ v6不同意。
vector
of auto_ptr
is always invalid, although Visual C++ v6 disagreed.
这篇关于C ++ std :: auto_ptr复制构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!