6.11 DESTRUCTORS
Just opposite to a constructor, C++ defines destructor. This is a member function of a class. It is used to destroy an object (of course, after we have used it). The basic rules regarding destructor may be stated as follows:
- A destructor need not be defined at all. The program will use a default destructor on its own. We may call it as system supplied destructor. This is a typical do-nothing destructor.
- A destructor may be declared and defined. There cannot be any return type associated with the destructor.
- A destructor has tilde (~) character followed by a class name.
- Destructors cannot be overloaded in g++ compiler. Turbo C++ allows us to overload destructors.
- It can be called simply as ~PERIOD(); If it has to be called in ...
Get Object Oriented Programming with C++, Second Edition 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.