C++综合系列之构造函数执行于main函数之前

来源:互联网 发布:cydia 数据库错误 编辑:程序博客网 时间:2024/05/21 16:12
#include<iostream>using namespace std;class Pre_Main{public:    Pre_Main()    {        cout << "I'm before main!" << endl;    }    ~Pre_Main()    {        cout << "I'm after main!" << endl;    }};//在C++中,利用全局变量和构造函数的特性,通过全局变量的构造函数执行;Pre_Main pre_Main;void main(){    cout << "I'm in main!" << endl;}
原创粉丝点击