How to resolve g ++ warning with -std = c ++ 11: "auto_ptr is deprecated

Try -std=c++11

with a compiler g++

, I got a lot

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

      

What should be used instead auto_ptr

? Please provide an informative link or complete answer.

+3


source to share


2 answers


You can use std::unique_ptr

insteadstd::auto_ptr



And if you copied auto_ptr

, you should std::move

unique_ptr

.

+2


source


"What should be used instead auto_ptr

?"



Class representing the behavior of std::auto_ptr<>

the most closely std::unique_ptr<>

.

+1


source







All Articles