Error : ‘template<class> class std::auto_ptr’ is deprecated

Error : ‘template<class> class std::auto_ptr’ is deprecated

我正在使用 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

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

这是我的 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