Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason that C++11 gives up auto_ptr? [duplicate]

It gives up auto_ptr and adds unique_ptr and shared_ptr. Are they good enough to let c++ abandon auto_ptr? There must be sometimes auto_ptr could lead to bad results. Can anyone give me an example?

If it doesn't do bad C++11 will keep it rather than give up.

like image 719
Fanl Avatar asked Jan 24 '26 02:01

Fanl


1 Answers

Because unique_ptr is a better alternative for auto_ptr.

In particular, it was not possible to store an auto_ptr in a container. While you can store unique_ptr in a container.

like image 56
Yu Hao Avatar answered Jan 25 '26 16:01

Yu Hao