-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path多继承Emp.cpp
87 lines (79 loc) · 2.38 KB
/
多继承Emp.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* @Author: your name
* @Date: 2020-03-26 09:37:54
* @LastEditTime: 2020-04-01 10:58:14
* @LastEditors: Please set LastEditors
* @Description: 多继承中的二义性问题解决
* @FilePath: /test/test.cpp
*/
#include <iostream>
#include <string>
using namespace std;
class Teacher {
public:
Teacher(string nam, int a, string s, string add, string n, string t);
void display();
protected:
string name;
int age;
string sex;
string addr;
string number;
string title; // 职称
};
Teacher::Teacher(string nam, int a, string s, string add, string n, string t)
: name{nam}, age{a}, sex{s}, addr{add}, number{n}, title{t} {}
void Teacher::display() {
cout << "name: " << name << endl;
cout << "age: " << age << endl;
cout << "sex: " << sex << endl;
cout << "addr: " << addr << endl;
cout << "number: " << number << endl;
cout << "title: " << title << endl;
}
class Cadre {
public:
Cadre(string nam, int a, string s, string add, string n, string t);
void display();
protected:
string name;
int age;
string sex;
string addr;
string number;
string post; // 职务
};
Cadre::Cadre(string nam, int a, string s, string add, string n, string t)
: name{nam}, age{a}, sex{s}, addr{add}, number{n}, post{t} {}
void Cadre::display() {
cout << "name: " << name << endl;
cout << "age: " << age << endl;
cout << "sex: " << sex << endl;
cout << "addr: " << addr << endl;
cout << "number: " << number << endl;
cout << "post: " << post << endl;
}
class Teacher_Cadre : public Teacher, public Cadre {
public:
Teacher_Cadre(string nam, int a, string s, string add, string n, string t,
string t_post, float w);
void show();
private:
float wages;
};
Teacher_Cadre::Teacher_Cadre(string nam, int a, string s, string add, string n,
string t, string t_post, float w)
: Teacher(nam, a, s, add, n, t),
Cadre(nam, a, s, add, n, t_post),
wages(w){};
void Teacher_Cadre::show() {
Teacher::display();
cout << "post: " << post << endl;
cout << "wages: " << wages << endl;
};
int main() {
Teacher_Cadre tcadre1("Zhang", 24, "female", "Shanghai", "155", "Teacher",
"org", 8000.01);
tcadre1.show();
return 0;
}