-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter_15.cpp
63 lines (52 loc) · 1.42 KB
/
chapter_15.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
#include <map>
using namespace std;
//委托构造函数和继承构造函数
//https://www.bilibili.com/video/BV1bX4y1G7ks/?p=19&spm_id_from=pageDriver&vd_source=240260c8cdca141b2447105a672fe65e
//委托构造函数
class User {
public:
User(){}
explicit User(string user_name) {
this->user_name = std::move(user_name);
}
User(string user_name, int age): User(std::move(user_name)){
this->age = age;
}
User(string user_name, int age, int gender): User(std::move(user_name), age){
this->gender = gender;
}
void func(string name){
cout << "User->name: " << name << endl;
}
void func(string name, int age){
cout << "User->name: " << name << endl;
cout << "User->age: " << age << endl;
}
string user_name;
int age;
int gender;
};
class StudentUser: public User {
public:
//using 使用
using User::User;
using User::func;
StudentUser(string user_name, int age, int gender, int student_no): User(std::move(user_name), age, gender){
this->student_no = student_no;
}
void func(){
cout << "StudentUser->null" << endl;
}
private:
int student_no{};
};
int main(){
User* user = new User("vickllny");
StudentUser studentUser("vickllny", 28, 1);
studentUser.func();
studentUser.func("vickllny");
studentUser.func("vickllny", 28);
return 0;
}