Appendix B ◾ 357
A destructor is a special class function that bears the same name as the
class, preceded by the special character “~.” Like constructors, the destruc-
tor returns no value, not even void. Unlike constructors, the destructor
cannot be overloaded: each class has only one destructor and it takes no
arguments. e application programmer does not invoke the destructor.
e C++ compiler automatically patches in a call to the destructor when
a stack object goes out of scope, or when a heap object is deallocated via
the delete (or delete[]) operator. Essentially, the destructor is a cleanup
routine: it performs any actions, such as deallocating heap memory, that
must be executed before an object goes out of scope.
Although some C ...