This is the code I got from the internet... and how virtual keyword is working? i think this virtual keyword has something to do with this behaviour but I don't understand what it is.
class A {
int x;
public:
A(int i) { x = i; }
void print() { cout << x; }
};
class B : virtual public A {
public:
B()
: A(10)
{
}
};
class C : virtual public A {
public:
C()
: A(10)
{
}
};
class D : public B, public C {
};
int main()
{
D d;
d.print();
return 0;
}