1.

What are destructors in C++?

Answer»

A CONSTRUCTOR is automatically called when an object is first created. Similarly when an object is destroyed a FUNCTION called destructor automatically gets called. A destructor has the same name as the constructor (which is the same as the CLASS name) but is preceded by a tilde.

Example:

class A{ private: INT val; public: A(int x){ val=x; } A(){ } ~A(){ //destructor }}int main(){ A a(3); return 0;}


Discussion

No Comment Found