C++ Programming Code Examples C++ > Beginners Lab Assignments Code Examples Destructors in C++ Programming Destructors in C++ Programming A destructor is a special member function that works just opposite to constructor, unlike constructors that are used for initializing an object, destructors destroy (or delete) the object. #include <iostream> using namespace std; class HelloWorld{ public: //Constructor HelloWorld(){ cout<<"Constructor is called"<<endl; } //Destructor ~HelloWorld(){ cout<<"Destructor is called"<<endl; } //Member function void display(){ cout<<"Hello World!"<<endl; cout << "Happy Codings - C++ Programming Language Code Examples"; } }; int main(){ //Object created HelloWorld obj; //Member function called obj.display(); return 0; } 1) Name should begin with tilde sign(~) and must match class name. 2) There cannot be more than one destructor in a class. 3) Unlike constructors that can have parameters, destructors do not allow any parameter. 4) They do not have any return type, just like constructors. 5) When you do not specify any destructor in a class, compiler generates a default destructor and inserts it into your code.