When virtual inheritance IS a good design?

If you have an interface hierarchy and a corresponding implementation hierarchy, making the interface base classes virtual bases is necessary. E.g. struct IBasicInterface { virtual ~IBasicInterface() {} virtual void f() = 0; }; struct IExtendedInterface : virtual IBasicInterface { virtual ~IExtendedInterface() {} virtual void g() = 0; }; // One possible implementation strategy struct CBasicImpl … Read more

What is the VTT for a class?

The page “Notes on Multiple Inheritance in GCC C++ Compiler v4.0.1” is offline now, and http://web.archive.org didn’t archive it. So, I have found a copy of the text at tinydrblog which is archived at the web archive. There is full text of the original Notes, published online as part of “Doctoral Programming Language Seminar: GCC … Read more

Virtual tables and memory layout in multiple virtual inheritance

Virtual bases are very different from ordinary bases. Remember that “virtual” means “determined at runtime” — thus the entire base subobject must be determined at runtime. Imagine that you are getting a B & x reference, and you are tasked to find the A::a member. If the inheritance were real, then B has a superclass … Read more

Why is Default constructor called in virtual inheritance?

When using virtual inheritance, the virtual base class’s constructor is called directly by the most derived class’s constructor. In this case, the daughter constructor directly calls the grandmother constructor. Since you didn’t explicitly call grandmother constructor in the initialization list, the default constructor will be called. To call the correct constructor, change it to: daugther(int … Read more

c++ virtual inheritance

virtual base classes are special in that they are initialized by the most derived class and not by any intermediate base classes that inherits from the virtual base. Which of the potential multiple initializers would the correct choice for initializing the one base? If the most derived class being constructed does not list it in … Read more