如下所示代码:
#include <iostream>
using namespace std;
class test{
public:
test()
{
cout << "this class constructor is called" << endl;
}
};
test global_test0;
test global_test1;
test global_test2;
int main(int argc, char *argv[])
{
cout << "define obj local_test start" << endl;
test local_test;
cout << "define obj local_test end " << endl;
while (1);
return 0;
}
输出的结果:
全局对象global_test0,global_test1,global_test2的构造函数在main函数之前执行。