I'm using auto_ptr<>
which uses an array of class pointer type so how do I assign a value to it.
e.g.
auto_ptr<class*> arr[10];
How can I assign a value to the arr
array?
Why is auto_ptr deprecated? It takes ownership of the pointer in a way that no two pointers should contain the same object. Assignment transfers ownership and resets the rvalue auto pointer to a null pointer. Thus, they can't be used within STL containers due to the aforementioned inability to be copied.
The C++11 standard made auto_ptr deprecated, replacing it with the unique_ptr class template. auto_ptr was fully removed in C++17.
The auto_ptr transfers the ownership of internal resource during a copy operation. Furthermore, such a behavior happens in both the cases of copy. That is whenever a new auto_ptr is constructed using copy constructor or whenever an assignment operation happens.
std::auto_ptr auto_ptr is a smart pointer that manages an object obtained via new expression and deletes that object when auto_ptr itself is destroyed.
You cannot use auto_ptr with array, because it calls delete p
, not delete [] p
.
You want boost::scoped_array or some other boost::smart_array :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With