#include <iostream>
#include <string>
using namespace std;
class Base
{
public:
Base()
{
cout << "Base"<<endl;
}
~Base()
{
cout << "~Base"<<endl;
}
};
class Child: public Base
{
public:
Child()
{
cout << "Child"<<endl;
}
~Child()
{
cout << "~Child"<<endl;
}
};
int main()
{
try
{
Child cc;
}
catch(...)
{
}
return 0;
}
the general output will be
Base
Child
~Child
~Base
But if something terrible or exception caught while Base is constructor ,then is it possible that the sequece will be :
Base
~Base
Child
~Child
Can anyone write a demo to illustate this? C++ usually doesn't throw exception in the constuctor, but if it does, then could it leads to that output?
Thanks for all helping. I am not sure that in usually code ,this could happens. Is it possible in complicated Base constructor or something wrong or whatever,that will change the usual output ? If so, can anyone give me one example?