Let's say I have a class serving as a stack called Pole, with the class of stuff that it actually contains being Disc. That is, class Pole is a stack of class Disc. Furthermore let's say that the push function is void Pole-push(Disc* arg), and that the pop function is Disc* Pole-pop(). Furthermore I have a function called void Pole-empty(), which deletes all Discs in the Pole stack from memory and empties the Pole.
I'm running into a little bit of an issue remembering how to completely empty the Pole of Discs with regards to whether I should or should not use the delete keyword.
The specific problem I'm running into is illustrated in this example. Let's say I have a class that holds a Pole variable called aPole. Furthermore let's say two functions in that class are as follows:
Code:
void func1()
{
Disc aDisc;
Disc anotherDisc;
aPole.push(&aDisc);
aPole.push(&anotherDisc);
}
void func2()
{
func1();
aPole.empty();
}
In this case, does the code in the definition for the void Pole-empty() function need to have the delete keyword to kill the Discs manually?
I used to think of using delete if and only if the keyword new were used earlier. But here the keyword new is never used. But the Discs live on even after going out of scope (the exit of func1()). If aPole were to lose all track of those Discs from its empty() function being employed in func2() WITHOUT using the delete keyword, what's keeping those Discs from just wasting memory? Also wouldn't the destructor for Pole need to use the keyword delete?
Thanks in advance!