构造函数 拷贝构造函数 析构函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
using namespace std;
class student
{
private:
int id;
int age;
public:
student()
{
id=1;
age=20;
}
  ~student()
  {
 cout<<"释放"<<id<<"的内存"<<endl;
  }
  student(student &p)
  {
 id=p.id +1;
 age=p.age+1;


  
  }
  void show()
  { cout<<"调用show函数:"<<endl;
cout<<id<<age<<endl;


  
  }
};






void main()
{
student a;
student b (a);
a.show();
b.show();
//先定义的后释放




}