Destructor

 avatar
narendra
c_cpp
a month ago
423 B
2
Indexable
#include <iostream>
using namespace std;

class Rectangle{
  public:
  int l;
  int b;
  
  Rectangle (){
    l=0;
    b=0;
  }
  Rectangle (int x , int y){
    l = x;
    b = y; 
  }
 
 ~ Rectangle (){
   cout<<"Detructors is called"<<endl;
 }
 
};

int main(){
  Rectangle* r1 = new Rectangle ();
  cout<<r1->l<<""<<r1->b<<endl;
  delete r1;
  
  Rectangle r2(3,4);
  cout<<r2.l<<""<<r2.b<<endl;
  
  
  
  
  return 0;
}
Leave a Comment