#include <iostream>
using namespace std;
class A
{
public:
A(){cout<<"Constructing A \n";}
~A(){cout<<"Destructinf A \n";}
int x;
};
class B : virtual public A
{
public:
B(){cout<<"Constructing B \n";}
~B(){cout<<"Destructinf B \n";}
int x=20;
};
class C : virtual public A
{
public:
C(){cout<<"Constructing C \n";}
~C(){cout<<"Destructinf C \n";}
int x=50;
};
class D : public B,public C
{
public:
D(){cout<<"Constructing D \n";}
~D(){cout<<"Destructinf D \n";}
};
int main()
{
D obj;
obj.x; //x invoked
cout<<obj.x<<"\n";
return 0;
}
Output error: request for member ‘x’ is ambiguous
Although I have used virtual class, still I am getting the above error.Do I have to remove One of the x declared in class B and Class C or is there any way to solve this error