#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "construct" <<endl;
}
~A()
{
cout << "destory" << endl;
}
};
A p;
int main()
{
A p1;
return 0;
}
struct GlobalBracket
{
GlobalBracket()
{
std::cout << "Initialize/n";
}
~GlobalBracket()
{
std::cout << "Clean up/n";
}
} global_bracket_variable;
输出的结果:
construct
Initialize
construct
destory
Clean up
destory
此为用g++编译结果。如果是在VC6下编译时,由于cout这个对象在全局变量析构前已经被析构,所以全局变量里面的“destory”无法打印。