//ambiguity of multiple inheritance--Virtual base class (knowledge-based)#include <iostream>using namespacestd;/*multiple inheritance is generally not used in current project development, he will increase the complexity of the project*/classpoint{ Public: Point () {x=1; Y=1; } intx; inty;};classPointa:Virtual Publicpoint{ Public: Pointa () {a=2; } intA;};classPOINTB:Virtual Publicpoint{ Public: Pointb () {b=3; } intb;};classPOINTC: PublicPointa, Publicpointb{};voidProtecta () {POINTC pc1; //pc1.x = 1; Error C2385: Access to "X" is ambiguous//At this point we can use the virtual keyword to decorate the inheritance relationshipPC1.Y =2; //The virtual keyword can detect that both Pointa and POINTB are inherited from point, so pc1.y = 2; is assigning a value to a point class object}voidMain () {protecta (); System ("Pause");}
C + + class inheritance Five (ambiguity of multiple inheritance--Virtual base class)