#include<bits/stdc++.h>
using namespace std;
class A {
public :
~A(){
cout << " A is destroyed " << endl;
}
};
class B : public A
{
public :
~B(){
cout << " B is destroyed " << endl;
}
};
int main()
{
B obj;
B * p = &obj;
delete p;
return 0;
}
In the main function I am creating only one object of class B, which inherits class A. When I am deleting that object using the pointer , destructor is called and prints message But then , I am not able to understand that why destructor is called twice ?