You cannot do a global find/replace because you can copy an auto_ptr
(with known consequences), but a unique_ptr
can only be moved. Anything that looks like
std::auto_ptr<int> p(new int);
std::auto_ptr<int> p2 = p;
will have to become at least like this
std::unique_ptr<int> p(new int);
std::unique_ptr<int> p2 = std::move(p);
As for other differences, unique_ptr
can handle arrays correctly (it will call delete[]
, while auto_ptr
will attempt to call delete
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…