8

I understand virtual in the context of a member function, like virtual void frob(). But what does it mean in the context of the class declaration, like class Foo : public virtual Bar?

For a given method there are 8 cases stemming from the presence or absence of virtual in the following three locations: 1) a superclass's functions; 2) the inheritance chain for this class; 3) this class's functions.

I think I understand how 1) and 3) interact, but 2) seems redundant. Is it? What am I not understanding?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Samuel Danielson
  • 5,231
  • 3
  • 35
  • 37
  • 1
    Does this answer your question? [In C++, what is a virtual base class?](https://stackoverflow.com/questions/21558/in-c-what-is-a-virtual-base-class) – Karl Knechtel Oct 07 '22 at 07:24

1 Answers1

11

That's virtual inheritance, you do it when you know you'll be doing multiple inheritance. That page goes into way more detail.

Steve M
  • 8,246
  • 2
  • 25
  • 26