Demonstrate ambiguity in multiple inheritance - C++ Class

C++ examples for Class:Inheritance

Description

Demonstrate ambiguity in multiple inheritance

Demo Code

#include <iostream>
using namespace std;
class A//  w  w  w  .  ja v  a2s. c om
{
   public:
   void show()  { cout << "Class A\n"; }
};
class B
{
   public:
   void show()  { cout << "Class B\n"; }
};
class C : public A, public B
{
};
int main()
{
C objC;            //object of class C
// objC.show();       //ambiguous--will not compile
objC.A::show();    //OK
objC.B::show();    //OK
return 0;
}

Result


Related Tutorials