void deleteAllNodes ()
{
stack <parentBranch *> mystack;
// `trunk` is the existing head node
mystack.push (trunk);
cout << mystack.top ()->content;
}
In this case a “copy” of trunk gets pushed in the stack? So, does this means that at a time there are two trunks present in the memory?
Nope.
trunkpoints to an object, but isn’t the object itself. Like a sign that reads “Car –>” next to a car. When you pushtrunkontomystack, you don’t get another car. You just get another sign pointing to the same car.Woe be it if you drive the car off (i.e.
delete trunk;). Then you’ll have a whole bunch of signs that point to a car, but when someone comes along and tries to get in that car, they’ll fall flat on their rear. All the signs pointing to the car will be liars.