auto_ptr
Deprecated class of smart pointers in C++ / From Wikipedia, the free encyclopedia
Dear Wikiwand AI, let's keep it short by simply answering these key questions:
Can you list the top facts and stats about Auto ptr?
Summarize this article for a 10 year old
In the C++ programming language, auto_ptr is an obsolete smart pointer class template that was available in previous versions of the C++ standard library (declared in the <memory>
header file), which provides some basic RAII features for C++ raw pointers. It has been replaced by the unique_ptr
class.
The auto_ptr
template class describes an object that stores a pointer to a single allocated object that ensures that the object to which it points gets destroyed automatically when control leaves a scope.[1]
The characteristics of auto_ptr
are now considered unsatisfactory: it was introduced before C++11's move semantics, so it uses copying for what should be done with moves (and confusingly sets the copied-from auto_ptr
to a NULL pointer). These copy semantics mean that it cannot be used in STL containers.[2]
The C++11 standard made auto_ptr
deprecated, replacing it with the unique_ptr
class template.[3][4] auto_ptr
was fully removed in C++17.[5]
For shared ownership, the shared_ptr
template class can be used. shared_ptr
was defined in C++11 and is also available in the Boost library for use with previous C++ versions.[6]