Take a look at this code, why will it not display "CleanUP" after it exits Main? I have tried writting it many different ways. Simple code, unexpected results?

Initialize
HelloWorld.......No Clean Up?

#include <iostream>
using namespace std;
class display
{
public:
display() { cout << "Initialize\n"; }
~display() { cout << "Clean up\n"; }
};
display d;

int main()
{
cout <<"Hello World!\n";
cin.get();
return 0;
}

I'm concerned that you've been here for a while now, and you still haven't figured out this CODE tags deal.

Edited 3 Years Ago by happygeek: fixed formatting

I'm using Bloodshed C++ compiler, I am starting to think it's a compiler issue. But I compiled it using Vis C++, no deals?

I'm using Bloodshed C++ compiler, I am starting to think it's a compiler issue. But I compiled it using Vis C++, no deals?

whatever you are using, if it does not cause the destructor of statics to be called (unless abort() was called), it is not a C++ compiler. the probable reason though, is that the window is disappearing too fast for you to make out what is going on.

That is why I'm using CIN.GET() so I can see what's being output to the screen.

That is why I'm using CIN.GET() so I can see what's being output to the screen.

cin.get() is inside main; destructors of statics are called (in reverse order of construction) after main returns (or exit is called). put your cin.get() as the last statement in your destructor (if that is the way you want to make a window stay).

Awesome, thanks it worked. To think I never thought of doing that? That's why I love this forum and can't wait to to become a better programmer, so I can help others.
Thanx Vijayan

Unrelated to your answer, but some knowledge you should know....

There's no such thing as a deconstructor in C++. Only Constructors and Destructor :)

This article has been dead for over six months. Start a new discussion instead.