Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming

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

5.00/5 (2 votes)
31 Aug 2010CPOL 5.4K  
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)