Destructor

A class destructor is called automatically when a class goes out of scope, and is used to clean up and free resources acquired by the object along its lifetime.

 

As with the Constructor, the Destructor uses the same name as the class but is prefixed with a ~ tilde.

 

Destructors take no parameters and have no return value.

 

This example show the destructor between lines 17 to 19, with an added "Object destroyed" message for info:

Leave a Reply