0

Let's consider the following code snippet:

struct A { void f(); };
struct B : virtual A {};
struct C : virtual A {};
struct D : B, C {};

What can I say? that D has two different member functions B::A::f and C::B::f which are called over a same object? or they are just aliases of a same member function?

For example, for the non-virtual case,

struct A { void f(); };
struct B : A {};
struct C : A {};
struct D : B, C {};

D has two different member functions B::A::f and C::A::f because they just have different names, so, calling D().f() is an ambigüity because I have to specify to which member I want to call.

However, in the virtual inhericante case, that isn't required anymore because calling by one path or another resolves to call the function over a same object, and I don't know anymore if, in the virtual inheritance case, I have two different member functions which resolves or are executed over a same object, or they are just aliases of a same member function.

Anyway, from a practical point of view that difference doesn't matter, but from a more formal point of view I'm not sure about what to say.

ABu
  • 10,423
  • 6
  • 52
  • 103

1 Answers1

2

In the virtual inheritance case you have D::A::f() and no specific overridden versions in the two middle inheritance levels.

D().B::A::f() works for the same reason that it works in this straightforward case (it inherits the parent version):

struct A { void f(); };
struct B : A {};
struct D : B {};
Mark B
  • 95,107
  • 10
  • 109
  • 188
  • If that were the case, how does `D().B::A::f()` even compile, if `D` has no such a member function? – ABu Aug 29 '17 at 18:29