65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Aug 31, 2010

CPOL
viewsIcon

5440

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 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.