php网站开发百度云,想建一个免费的网站,定制软件开发报价,wordpress底部热门标签多继承 多继承#xff1a;派生类继承多个基类#xff08;继承多父类特性#xff09; 语法#xff1a;class 派生类名: 继承方式1基类名1 , 继承方式2基类名2 , ...{ 派生类类体; } 1 #include iostream2 3 using … 多继承 多继承派生类继承多个基类继承多父类特性 语法class 派生类名: 继承方式1基类名1 , 继承方式2基类名2 , ...{ 派生类类体; } 1 #include iostream2 3 using namespace std;4 5 class info1 {6 public:7 void setter1(int a) {8 num1 a;9 }
10
11 protected:
12 int num1;
13
14 private:
15 int age1;
16 };
17
18 class info2 {
19 public:
20 void setter2(int a) {
21 num2 a;
22 }
23
24 protected:
25 int num2;
26
27 private:
28 int age2;
29
30 };
31
32 class info : public info1, public info2 {
33 public:
34 void fun(void) {
35 int a;
36 a num1 num2;
37 cout a endl;
38 }
39
40 protected:
41 int num3;
42
43 private:
44 int age3;
45 };
46
47
48 int main(void)
49 {
50 info text;
51
52 /* text.num1; 由于多继承方式为public所以派生类不能直接访问protected与private
53 text.age2;
54 */
55
56
57 text.setter1(33);
58 text.setter2(44);
59 text.fun();
60
61 return 0;
62 } 笔记 转载于:https://www.cnblogs.com/panda-w/p/11368476.html