-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
40 lines (40 loc) · 748 Bytes
/
test.cpp
File metadata and controls
40 lines (40 loc) · 748 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
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
class Base0
{
public:
Base0(int var) : var0(var) {}
int var0;
void fun0() { cout << "Member of Base0" << endl; }
};
class Base1 : virtual public Base0
{
public:
Base1(int var) : Base0(var) {}
int var1;
};
class Base2 : virtual public Base0
{
public:
Base2(int var) : Base0(var) {}
int var2;
};
class Derived : public Base1, public Base2
{
public:
Derived(int var) : Base0(var), Base1(var), Base2(var)
{
}
int var;
void fun()
{
cout << "Member of Derived" << endl;
}
};
int main()
{ //程序主函数
Derived d(1);
d.var0 = 2; //直接访问虚基类的数据成员
d.fun0(); //直接访问虚基类的函数成员
return 0;
}