1 #include <iostream> // 标准的输入输出
2 using namespace std;
3
4 class Person {
5 public:
6 Person()
7 {
8 ¦ cout << "调用默认构造函数" << endl;
9 }
10
11 ~Person()
12 {
13 ¦ cout << "调用默认析构函数" << endl;
14 }
15 };
16
17 void test01()
18 {
19 Person* p = new Person;
20 delete p;
21 }
22
23 void test02()
24 {
25 Person* array = new Person[10];
26 delete[] array;
27 }
28
29 int main()
30 {
31 test01();
32 test02();
33 return 0;
34 }
c++ new和delete运算符
最新推荐文章于 2024-11-18 18:38:00 发布