//多继承的二义性--虚基类(了解为主)
#include<iostream>
using namespace std;
/*
多继承在现在的项目开发中一般不使用,他会增加项目的复杂度
*/
class Point{
public:
Point(){
x = 1;
y = 1;
}
int x;
int y;
};
class PointA :virtual public Point{
public:
PointA(){
a = 2;
}
int a;
};
class PointB :virtual public Point{
public:
PointB(){
b = 3;
}
int b;
};
class PointC :public PointA, public PointB{
};
void ProtectA(){
PointC pc1;
//pc1.x = 1; 报错 error C2385 : 对“x”的访问不明确
//这时候我们可以使用 virtual关键字修饰继承关系
pc1.y = 2;
//virtual关键字可以检测出PointA和PointB都是从Point继承,所以pc1.y = 2;是给Point类对象赋值
}
void main(){
ProtectA();
system("pause");
}