Saturday, 10 March 2018

Destructor In C++

Destructor is a member function which destructs or deletes an object.
It destructs the objects of classes.
It can be defined only once in a class.
It is invoked automatically when the object goes out of scope.
Destructors have same name as the class name preceded by a tilde (~).
Destructors don’t take any argument and don’t return anything
Example:
#include <iostream.h> 
#include<conio.h>
class A
 { 
   public: 
        A()   
        {   
            cout<<"Hello,Welcome to LearningPoint92"<<endl;   
        }   
        ~A()   
        {   
            cout<<"Destructor Example "<<endl;   
        } 
}; 
void main()  
{ 
    clrscr();
    A a1;
   getch();
} 
Output:
Hello, Welcome to LearningPoint92


No comments:

Post a Comment

Global Infrastructure and its components in AWS

You may operate your workloads wherever and however you choose with the AWS Global Infrastructure, and you'll use the same network, cont...