当使用成员实例
1。一个虚拟基类提供,一个是后续derived类提供时,无二义
因为后续优先
后续指虚拟基类的后续
class A
{
public:
void ok(){cout << "A::okokok" << endl;}
};
class B:public virtual A
{};
class C:public virtual A
{
public:
void ok(){cout << "C::okokok" << endl;}
};
class D:public B, public C
{};
int main()
{
D d;
d.ok();
return 0;
}
2。一个虚拟基类提供,另个非虚拟基类的后续derived类提供时,二义
class A
{
public:
void ok(){cout << "A::okokok" << endl;}
};
class B:public virtual A
{};
class C:
{
public:
void ok(){cout << "C::okokok" << endl;}
};
class D:public B, public C
{};
int main()
{
D d;
d.ok();
return 0;
}
3。优先范围:虚拟基类与其的后续类
1。一个虚拟基类提供,一个是后续derived类提供时,无二义
因为后续优先
后续指虚拟基类的后续
class A
{
public:
void ok(){cout << "A::okokok" << endl;}
};
class B:public virtual A
{};
class C:public virtual A
{
public:
void ok(){cout << "C::okokok" << endl;}
};
class D:public B, public C
{};
int main()
{
D d;
d.ok();
return 0;
}
2。一个虚拟基类提供,另个非虚拟基类的后续derived类提供时,二义
class A
{
public:
void ok(){cout << "A::okokok" << endl;}
};
class B:public virtual A
{};
class C:
{
public:
void ok(){cout << "C::okokok" << endl;}
};
class D:public B, public C
{};
int main()
{
D d;
d.ok();
return 0;
}
3。优先范围:虚拟基类与其的后续类