析构函数是系统收回内存做的操作,遵循先构造的后析构原则,静态内存区的最后析构
#include <iostream>
using namespace std;
class T
{
public:
T(int n)
{
num = n;
cout<<"num"<<num<<" "<<"构造"<<endl;
}
~T()
{
cout<<"num "<<num<<" "<<"析构"<<endl;
}
private:
int num;
};
T t1(1);
void F()
{
static T t3(3);
T t4(4);
}
int main()
{
T t2(2);
{
T t5(5);
F();
}
return 0;
}
代码运行