In this post, we will see Ambiguity in Multiple Inheritance in C++ with Solution
Program Code (ambiguity.cpp):
#include<iostream>
using namespace std;
class A
{
public:
int x=3;
void show()
{
cout<<"In A show function with value of x:"<<x<<endl;
}
};
class B
{
public:
int x=5;
void show()
{
cout<<"In B show function with value of x:"<<x<<endl;
}
};
class C: public A, public B
{
};
int main()
{
C obj;
//obj.show();
obj.A::show(); //obj.A::x;
obj.B::show();
cout<<"Value of x from class A:"<<obj.A::x<<endl;
cout<<"Value of x from class B:"<<obj.B::x<<endl;
}
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=sWMV5rM58yQ
No comments:
Post a Comment