Destructors

A C++ object is destroyed either at the end of program execution (for extern and static objects), at the exit from the closing brace of a scope (for automatic objects), when the operator delete is executed (for dynamic objects allocated with new), or when the library function free() is called (for objects allocated with malloc()).

Whenever a class object is destroyed (with the exception of the call to free()), the class destructor is called immediately before the destruction; if the class defines no destructor, the system-supplied default destructor is called (similar to default constructor, it does nothing).

A programmer-supplied destructor, similar to a constructor, is a class member function. Destructor syntax is even more rigid ...

Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.