1 class A
2 {
3 public:
4 A();
5 ~A();
6 int get()const{return *i;}
7 void set(int x){*i=x;}
8 private:
9 int *i;
10 };
11 int main()
12 {
13 A *p=new A;
14 cout<<p->get()<<endl;
15 p->set(0);
16 cout<<p->get()<<endl;
17 delete p;
18 return 0;
19 }
20 A::A()
21 {
22 cout<<"构造函数执行中...\n";
23 i=new int(999);
24 }
25 A::~A()
26 {
27 cout<<"析构函数执行中...\n";
28 delete i;
29 }