c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated

标签 c++ c++11 g++ scons

我正在使用 scons 和 ubuntu。 当我使用'scons'制作一些程序时,会发生错误,例如,

src/db/DBTextLoader.cc:296:3: error: ‘template class std::auto_ptr’ is deprecated [-Werror=deprecated-declarations]

/usr/include/c++/5/bits/unique_ptr.h:49:28: note: declared here template class auto_ptr;

这是我的命令;

$ ./configuer

$ source something.sh

$ scons

其实我也不知道。我已经在搜索这个网站和谷歌了。但是我没有找到解决方案。

这是我的 g++ 版本(和 c++ 也是相同的版本。)

g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

有什么想法吗? 谢谢。

最佳答案

如果你读过 Scott Meyers 的一些书,他强烈建议不要使用 auto_ptr。实际上,新的编译器可能会限制它的使用,因为在 STL 容器等中使用 auto_ptr 时可能会出现很多问题。

相反,如果您不想要对象的多个拷贝,则应使用 std::unique_ptr,如果需要复制,则应使用 std::shared_ptr指针。

关于c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45053626/

相关文章:

c++ - OpenCV Mat 导致 SIGABRT 崩溃

c++ - 获取错误流浪 ‘\342’ 和 ‘\200’ 和 ‘\214’

c++ - 尝试使用 Android-NDK 生成 so 文件时,未在此范围内声明“runtime_error”

c++ - 读取 system() 命令错误响应消息

C++11:std::mem_fn 的类型名称

c++ - 在这种情况下如何正确释放内存

c++ - 我无法运行将 allegro5 与 cmake 结合使用的程序

作为类成员的智能指针的 C++11 索引 vector

c++ - 如果传入 std::swap 的对象在交换期间抛出异常怎么办?

c++ - 如何使用 std::regex 查找字符串中的下一个匹配项?