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

orde.r picture orde.r · Jul 12, 2017 · Viewed 7.3k times · Source

I'm using scons and ubuntu. When i when i make some program in using 'scons', there happen error like,

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;

and this is my command;

$ ./configuer

$ source something.sh

$ scons

Actually, I don't have any idea. I'm already searching this site and google. But I didn't find solution.

this is my g++ version (and c++ also was same version.)

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

have any idea? Thank you.

Answer

banana36 picture banana36 · Jul 12, 2017

If you read some books of Scott Meyers, he strongly recommends not to use auto_ptr. Actually, new compilers may restrict it's usage because of lots of possible problems with it when using auto_ptr in STL containers, etc.

Instead, you should use std::unique_ptr if you don't want more that one copy of the object, and std::shared_ptr if you need to copy the pointer.