Is it safe and/or good practice to do something as the following?
//NewList is a member function of a class
void NewList(int size){
delete[] list; //list is a member variable; an already initialized dynamic array.
list=new ListObject[size];
}
I'm basically discarding the previous array because I will use different data to store in the class, and hence require a new list to store other information on the new data. If this is not good practice, what's the alternative?
std::vectordeletewas going to invalidate the pointer, so when I want to reuse it, I thought maybe I should keep a list of allocated memory addresses and only usedeleteon the whole list before the end of the program. I'll read the link "Rule of Three" in a few moments.