Code below shows base class (GrandParent) have a virtual function (show()) and two virtually derived classes (Parent1 and Parent2) with each having their own implementation of show(). Class Child inherits both Parent1 and Parent2 and implements it's own version of show().
In the code below, I have a new object (Parent2 *objP = new Child();) and calling objP->show(). I expected this to call the show() function of Parent2 (and return 9). However it is actually calling show() function of Child (and hence returning 7).
I understand that show() was virtual function of GrandParent but it is not a virtual function for Parent2. Hence confused why is objP->show() calling show() of Child and not for Parent2.
Thanks for your help.
class GrandParent {
 public:
      int virtual show() { return 10; }
};
class Parent1 : public virtual GrandParent {
 public:
      int show() { return 1; }  
};
class Parent2 : public virtual GrandParent {
 public:
      int show() { return 9; }  
};
class Child : public Parent1, public Parent2 {
 public:
      Child(){}
      int show() { return 7; }  
};
int main() {
      GrandParent *objGrand = new Child();
      GrandParent *objGrand1 = new Parent1();
      Parent2 *objP = new Child();
      Child *objChild = new Child();
      cout << objGrand->show()  << endl;// get 7 as expected
      cout << objP->show()  << endl; // get 7 instead of 9 expected
      cout << objChild->show()  << endl; // get 7 as expected
      cout << objGrand1->show()  << endl; // get 1 as expected
      return 0;
}

