Destructor
Destructor
Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed. A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
For example:
class ABC {
public:
// Constructor for class ABC
ABC();
// Destructor for class ABC
~ABC();
};
A destructor takes no arguments and has no return type. Its address cannot be taken. Destructors cannot be declared const, volatile, const volatile or static. A destructor can be declared virtual or pure virtual.
If no user-defined destructor exists for a class and one is needed, the compiler implicitly declares a destructor. This implicitly declared destructor is an inline public member of its class.
Posted in Computer Science, Information Technology, Object Oriented Programming, Object Oriented Programming |
