【问题标题】:how to resolve g++ warning with -std=c++11: ‘auto_ptr’ is deprecated [duplicate]如何使用 -std=c++11 解决 g++ 警告:不推荐使用“auto_ptr”[重复]
【发布时间】:2015-04-25 13:12:23
【问题描述】:

g++ 编译器尝试-std=c++11,我得到了很多

warning: ‘auto_ptr’ is deprecated (declared at 
/usr/include/c++/4.8/backward/auto_ptr.h:87) [-Wdeprecated-declarations]

我应该使用什么来代替auto_ptr?请提供信息链接或完整答案。

【问题讨论】:

标签: c++ c++11 g++


【解决方案1】:

您可以使用std::unique_ptr 代替std::auto_ptr

如果您复制了auto_ptr,则必须将std::move 复制到unique_ptr

【讨论】:

    【解决方案2】:

    “我应该用什么来代替auto_ptr?”

    最接近代表std::auto_ptr<> 行为的类是std::unique_ptr<>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 2020-01-31
      • 2017-01-22
      • 2017-11-12
      • 1970-01-01
      • 2013-03-06
      • 2011-04-11
      相关资源
      最近更新 更多