Click here to Skip to main content
15,886,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Posted
Updated 23-Apr-14 22:42pm
v3

1 solution

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
 
Share this answer
 
Comments
Nelek 24-Apr-14 5:28am    
Nice Links
Sergey Alexandrovich Kryukov 24-Apr-14 11:51am    
Thank you, Nelek.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900