C ++ std :: auto_ptr复制构造函数 [英] C++ std::auto_ptr copy constructor

查看:226
本文介绍了C ++ std :: auto_ptr复制构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆