新手:请大神指导:在构造函数中开辟内存空间:这个程序的执行过程是怎样的
1 class A2 {
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 }