//pafone 2010.07.10
//在main之前做些工作
[code]
#include <iostream>
using namespace std;
class Bootstrap
{
public:
Bootstrap();
void dosomething_beforemain();
};
Bootstrap::Bootstrap()
{
cout << "Bootstrap constructor" << endl;
dosomething_beforemain();
}
void Bootstrap::dosomething_beforemain()
{
cout << "hahahaha, i am before main" << endl;
}
Bootstrap bootstrap;//关键在main前实例化一对象
int main()
{
cout << "main" << endl;
system("pause");
}
[/code]
运行结果:
Bootstrap constructor
hahahaha, i am before main
main
请按任意键继续. . .