-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathT32.cpp
More file actions
31 lines (26 loc) · 799 Bytes
/
Copy pathT32.cpp
File metadata and controls
31 lines (26 loc) · 799 Bytes
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
#include <iostream>
#include "Student.h"
using namespace std;
/**
* 构造函数详解
* @return
*/
int main32() {
//堆区开辟空间
Student *student = new Student();
Student *student2 = new Student("有参数构造函数");
student->setAge(232);
student->getAge();
cout << "student age:" << student->getAge() << endl;
student2->getName();
cout << "student2 name:" << student2->getName() << endl;
//栈区开辟空间
Student *student3 = new Student("有参数构造函数", 23);
cout << "name:" << student3->getName() << ",age:" << student3->getAge() << endl;
delete student3;//析构函数执行
delete student2;
delete student;
// free(student3) new 对象此方式不规范
// malloc 构造函数不执行
return 0;
};