C++ : Constructors And Destructors 8

Destructors

A destructor function is a special function which if present automatically gets executed whenever an object goes out of scope i.e. gets destroyed.

Properties

• Name of the destructor function is exactly same as that of the class except that it is preceded by a special symbol ~ (tilde).
• It has no return type not even void
• Destructor function if present automatically gets executed whenever an object goes out of scope i.e. gets destroyed.
• It cannot be invoked by an object of the class.
• We cannot pass any arguments to the destructor function.
• Destructor functions cannot be overloaded (Reason: because we cannot pass any arguments to the function).
• Destructor function gets executed in reverse order of the creation of the objects.

Question:
How many destructors can be present in one class?
Answer:
Only one. (Reason: as we cannot pass any arguments to the destructor function, and hence it cannot be overloaded.)

Question:
Can the destructor function be overloaded?
Answer:
No destructor function cannot be overloaded, as we cannot pass any arguments to a destructor function.

Number Of Visitors

0238236