Click here to Skip to main content
15,885,546 members
Articles / General Programming
Alternative
Tip/Trick

C++ Tip: Aware of the confusion between delete with delete[]

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
31 Aug 2010CPOL 5.4K   1  
A good exercise to aid in always using delete [] where appropriate is to code your own autoarray_ptr following the pattern of c++ auto_ptr. The destructor calls delete [] when the instance goes out of scope. Saves writing a lot of messy delete [] code in "if chains" and switch blocks....
A good exercise to aid in always using delete [] where appropriate is to code your own autoarray_ptr<class T> following the pattern of c++ auto_ptr. The destructor calls delete [] when the instance goes out of scope. Saves writing a lot of messy delete [] code in "if chains" and switch blocks. Stroustrup didn't include it in C++ Programming Language since he assumed once you had auto_ptr it was just boiler plate to code your own class for autoarray_ptr.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --