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

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...