If I want to delete a dynamically allocated array of primitive type values:
int *it = new int[10]
do I just put delete [] it in the destructor to take care of releasing memory properly?
OR
Realizing that, as a pointer is a primitive type, does deleting a dynamically allocated array involve doing something like this in the destructor:
for (size_t idx = 0; idx != 5; ++idx)
delete sp[idx];
delete[] sp;
I’m rather confused about this as I am having a lot of memory related errors in my program.
If you have:
the correct way to
deleteit is:If you have a member variable of this type you need to implement a copy constructor and assignment operator as the default versions of these are not sufficient or make the class uncopyable.
As this is C++ I would suggest using
std::vector<int>instead as this will handle the memory management for you.