What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"?
For a given method there are 8 cases stemming from the presence or absence of virtual in the following three locations.
I think I understand how numbers 1 and 3 interact but number 2 seems redundant. Is it? What am I not understanding?
virtual functions can be private . This is because private means that the function cannot be called by derived classes. It does not prevent the entry to the v-table being overwritten. This means that the both the base class and the derived class will have access to the overwritten virtual function.
A virtual function is a member function that you expect to be redefined in derived classes. When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class's version of the function.
As i said the "virtual" comes for free on free functions, you dont have to declare it as virtual, the only thing you have to do is to put a & next to the parameter.
That's virtual inheritance, you do it when you know you'll be doing multiple inheritance. That page goes into way more detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With