hi all,
Code:
#include <iostream>
using namespace std;
class A
{
public:
int i;
A(int i):i(i)
{
cout<<"A created "<<i<<endl;
}
~A()
{
cout<<" A Destroyed "<<i<<endl;
}
A()
{
cout<<"A() called"<<endl;
}
};
class B:public A
{
public:
B(int j):A(j)
{
cout<<"B created "<<i<<endl;
}
B(){ cout <<" B() called"<<endl;}
~B()
{
cout<<" B distroyed "<<i<<endl;
}
};
int main()
{
A a(100);
B b(200);
A j[] = {A(1),B(2)};
return 0;
}
the output of this would be
A created 100
A created 200
B created 200
A created 1
A created 2
B created 2
B distroyed 2
A Destroyed 2
A Destroyed 2
A Destroyed 1
B distroyed 200
A Destroyed 200
A Destroyed 100
can anyone tell me , how the distructor of B is called, after the initializationg ( A(int) is called, and then when creating B, A(int) is first called, and then B(int), which I understood, what I can't understand is why ~B() is called right after this)
Thank you in advance