In the following program
Code:
#include<iostream>
using namespace std;
void MyExit(void)
{
cout<<endl<<"Exit from function!"<<endl;
exit(0);
}
class MyClass
{
public:
MyClass(void)
{
cout<<endl<<"Object initialized!";
}
~MyClass()
{
cout<<endl<<"Object destoryed!"<<endl;
}
};
int main()
{
MyClass C1;
MyExit();
return 0;
}
The destructor is not executing. What is the reason?
Although I am not terminating the program in main() but still on termination C! should go out of scope which means that the dertructor should run. But it is not happening. Why?