I was reading Alex Alain's C++ pdf book (recommended buy btw), and the book says compiler will still call destructor even when it is not defined in my own class. I see it as destructor will automatically be called for automatic (aka: local) variabls so within a block so once reached the closing curly braces, and must be called for dynamically allocated variables so usingkeyword.Code:new
Is it correct to say automatic variables and parameters too are automatically destroyed b/c they are automatically removed from the stack (which is why beauty of recursion works as it can keep track of each moment of a variable), while pointer variables from the heap and so must explicitly call delete which will invoke the appropriate destructor?
So if I was to write a class that had no dynamically allocated members, then I don't have to define a destructor, right? The author uses a linked list class so a destructor makes sense, but is it safe to say I don't need to include my own destructor if I don't have any dynamically allocated variables b/c I wouldn't know what to include in it btw.
e.g.
Code:class Hockey_Player { public: int get_goals(); void print_stats(); Hockey_Player(); private: int goals; string name; int number_of_cup_rings; };