0

How to delete array of objects in C++? Proof by C++ code for proper deletion

17th May 2019, 4:49 PM
Deepesh Uikey
Deepesh Uikey - avatar
2 Respuestas
+ 1
//try this. Class_type pointer = NULL; pointer = new Class_type[16]; delete [ ] pointer; If you need proof they are all deallocated then you could add a message output to the class destructor. Or better yet create a static member that holds the number of objects.
18th May 2019, 12:57 AM
Jared Bird
Jared Bird - avatar
0
I'd say that, as objects are stored as pointer in an array, you can simply loop through the array and use the delete keyword to delete the pointers, then delete the array (no proof though, I don't really code in c++ anymore)
17th May 2019, 4:53 PM
ThewyShift
ThewyShift - avatar