Probably, you understand
auto_ptr
correctly, but your logic betrays you. Well, betrays… very badly. Yes, what you say is often better, so what? Does it make the automatic heap deallocation pointless in general? The problem should be posed correctly: it's not about what is better, heap or stack, this is about more particular thing: what is better when the use of the heap is already given?
You could possibly prove your point if you could prove that heap should not be used at all. If you cannot say so, you should not even suggest the alternative you suggested in your question, because, once heap is used, deallocation is a problem.
And if you wanted to state that heap is not needed (I want to assume, just for a second), it would mean that you did not understand that stack is 1) much more limited resource, 2) it cannot support free allocation needed for most more sophisticated structures (which are simple enough; the examples are the linked list and the tree, set aside general-structure graphs).
Also, note that
auto_ptr
is deprecated in C++11, superseded by more flexible and powerful
unique_ptr
:
http://www.cplusplus.com/reference/memory/auto_ptr[
^],
http://en.cppreference.com/w/cpp/memory/unique_ptr[
^].
—SA