构造函数和析构函数学习代码
1 #include <iostream> // 标准的输入输出
2 using namespace std;
3
4 class Person{
5 public: // 析构函数和构造函数的权限必须是public
6 Person(){
7 ¦ cout << "构造函数" << endl;
8 }
9
10 ~Person(){
11 ¦ cout << "析构函数" << endl;
12 }
13
14 };
15
16 void test01(){
17 Person p1;
18 }
19
20 int main()
21 {
22
23 test01();
24 return 0;
25 }