#include "stdafx.h"
#include "iostream"
#include <stdlib.h>
using namespace std;
int func() //必须为int返回值
{
cout<<"This is after main function"<<endl;
system("pause");
return 0;
}
int main(int argc,char*argv[])
{
onexit(func);
cout<<"This is main function"<<endl;
system("pause");
return 0;
}
#include "stdafx.h"
#include "iostream"
#include <stdlib.h>
using namespace std;
class A
{
public:
A()
{
cout<<"This is A's constructor"<<endl;
}
};
A a;
int main(int argc,char*argv[])
{
cout<<"This is the main function"<<endl;
system("pause");
return 0;
}
#include "stdafx.h"
#include "iostream"
#include <stdlib.h>
using namespace std;
class A
{
public:
A()
{
cout<<"This is A's constructor"<<endl;
}
~A()
{
cout<<"This is A's deconstructor"<<endl;
system("pause");
}
};
int main(int argc,char*argv[])
{
A(a);
system("pause");
return 0;
}
在main函数之外执行函数的情况,布布扣,bubuko.com
原文:http://blog.csdn.net/cjc211322/article/details/38702649