What is Destructor in C++

Every time when an object or instance of a class in created the constructor method is called. Destructor is used to release resource like memory releasing and file closing before coming out of the program. The program will create and destroy two constructors with destructor.

Source Code

      #include<iostream>
      using namespace std;
      class LEP
      {
      public:
       int num;
       LEP ()
       {
        cout<<"This is a Default Constructor        :"<<endl<<endl;
       }
       LEP (int a)
       {
       num = a;
       cout<<" This is Intilize Constructor         : "<<a<<endl<<endl; 
      }
      ~LEP ()
      {
       cout<<" Destructor Destruct the Construcers  : "<<endl<<endl;
      }
      };
      int main ()
      {
      cout<<"\t \t \t LEP Tutorials \n \n \n ";
      LEP L;
      LEP NB (4);
      }

Output of the Program

Destructor in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment