Monday, 26 April 2021

Virtual Destructor in C++

 #include<iostream.h>

#include<conio.h>

class A

{

public:

A()

{

 cout<<"C-A"<<endl;

}

virtual ~A()

{

cout<<"D-A"<<endl;

}

};

class B:public A

{

public:

B()

{

cout<<"C-B"<<endl;

}

~B()

{

cout<<"D-B"<<endl;

}


};

int main()

{

clrscr();

{

A *a=new B;

/*

A *a;

B b;

a=&b;

*/

delete a;

}

getch();


}

No comments:

Post a Comment