I'm using visual studio 2013 and printing some cout commands to test, When i debug my code, the control go inside the destructor of both class but it's not printing cout statement on console.
#include <iostream>
using namespace std;
class Uni
{
public:
~Uni()
{
cout << "I am in Uni Destructor" << endl;
}
Uni()
{
cout << "I am in Uni Constructor" << endl;
}
};
class Student: public Uni
{
public:
Student()
{
cout << "I am in Student Constructor" << endl;
}
~Student()
{
cout << "I am in Student Destructor" << endl;
}
};
int main()
{
Student s;
system("pause");
return 0;
}
Output:
I am in Uni Constructor
I am in Student Constructor
I suppose you get the output at this point, i.e. after the
pause.But at that point
sis still not destroyed. It will be destroyed when get out of the scope where it's declared, i.e. when get out of the functionmain.You can put
sinto further scope for testing.