Folks,
I've created 2 classes, called TEST1 and TEST2. In TEST1, I've declared a STL vector of the TEST2 class. Each time my program is run, there is a random number generated which specifies the number of instances of TEST2 that should be contained within the vector. That obviously required a initialisation function which I've written below
Code:
vector<TEST2> test2_list;
for (int i = 0; i < random_num; i++)
{
TEST2 *temp = new TEST2(param1, param2, param3);
test2_list.push_back(*temp);
}
This works great. It initialises the vector exactly as I need it.
My question is now on how do I delete the memory that I used with the new command once the program has stopped running.
Do I put in the deconstructor of TEST1 a command to clear the vector. Will that delete the memory ?
Code:
test2_list.clear();
Or do I need to put something in the deconstructor of TEST2 like
Unsure on how to delete this memory again once this program is complete. Obviously at the moment, I've got some memory leak so it's certainly a problem.
Any help, would be much appreciated.
Cheers
Starkhorn