标签:
#include<iostream>
using namespace std;
class A
{
public:
A(){cout<<"A construction\n";}//构造函数
~A(){cout<<"A Destruction\n";}//析构函数
};
int main() {
cout<<"构造a\n";
A a;
cout<<"构造pb\n";
A *pb=new A;
cout<<"--------------\n";
{
cout<<"构造c\n";
A c;//生命周期在大括号内
cout<<"析构c\n";
}
cout<<"------------------\n";
cout<<"析构pb\n";
delete pb;
cout<<"析构a\n";
return 0;
return 0;}
结果:
构造a
A construction
构造pb
A construction
--------------
构造c
A construction
析构c
A Destruction
------------------
析构pb
A Destruction
析构a
A Destruction
--------------------------------
Process exited after 0.1611 seconds
请按任意键继续. . .
标签:
原文地址:http://www.cnblogs.com/thefirstfeeling/p/5093340.html