#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
class Test{
private :
int x;
char *p;
public:
Test()
{
x = 10;
p = (char *)malloc(100); //初始化操作
strcpy(p, "123456789");
cout << "构造函数";
}
~Test(){ if(p!=NULL) free(p); cout << "析构函数"; }//释放资源
void print(){ cout << x << endl; cout << p << endl; }
};
void display()
{
Test t1, t2; //是先定义的先构造,然后后析构。
t1.print();
t2.print();
//后定义后构造,然后先析构。
}
int main()
{
display();
system("pause");
}