[Question]
Guess the result of the following codes.
class Object
{
public:
string name;
Object(const string name)
{
this->name = name;
cout << "Object::Object " << name << endl;
}
virtual ~Object()
{
cout << "Object::~Object " << name << endl;
}
};
Object globalObject("globalObject");
int main()
{
Object autoObject("autoObject");
exit(0); // _exit(0); (1)
}
[Result]
At (1), in case of exit() is called
Object::Object globalObject
Object::Object autoObject
Object::~Object globalObject
At (1), in case of _exit() is called
Object::Object globalObject
Object::Object autoObject
[Conclusion]
When exit() or _exit() are called, the destructors of auto objects(located in stack) are not called.
exit() calls the desctuctors of static(global) objects, while _exit() does not do it.
exit() terminates the calling process after cleanup, while _exit() does immediately.
[Download]
For more information, http://msdn.microsoft.com/en-us/library/6wdz5232(VS.80).aspx