thanks in advance for any help you can give. I am struggling with figuring out what exactly goes into a destructor because I haven't found a great explanation of really how you implement the idea with code. My textbooks and a couple of different things I've read explain that a destructor is essentially a method that is called for an abstract data type (ADT) that helps to release any resources/memory used by an ADT object. My textbook code example though literally just has a cout statement inside of the destructor that says "The object is about to be destroyed" which you can imagine isn't particularly helpful.
I am working on a stacks project where we're creating a stack of pointers to a struct object called Data (which does not have a destructor, read a little bit about why that is earlier) which contains two attributes: int ID and string data. Then the stack itself only has two attributes: int top (holds the top value for peek and pop functions) and the array of Data pointers.
So do I need to delete top and delete the stack of pointers? Can I just delete the stack of pointers as a whole or do I need to iterate through the stack and delete everything inside of it before deleting the stack array itself? If I do need to delete each pointer, can I just delete the pointer? Or do I need to figure out how to also delete the information that is inside of that memory location where the pointer is pointing? And do I do all of those things using the delete keyword?
Just trying to wrap my head around what all I need to specifically target when deleting things in the destructor. Once I know that much, I think that I can figure out how to do the actual writing by googling for syntax and testing out in the IDE/terminal, double checking things with the professor if syntax isn't quite working, etc.
Normally I'd ask these things to my professor in class, but the class itself is for data structures and algorithms so I don't want to interrupt those topics to ask something that feels sort of regressive. I think maybe these things were supposed to be covered in the prerequisite course but I took that class a while ago and it doesn't seem that these things were really covered well based on that textbook I still have (and there was no lecture because it was online).
I really want to learn these concepts deeply and understand the architecture behind them as much as possible so that I'm prepared well for writing good code and working in a professional environment. Thank you again for any help you all can give!