Virtual Public Class is used for a class to ensure that an object of a class inherits only one subobject.
class L { /* ... */ }; // indirect base class
class B1 : virtual public L { /* ... */ };
class B2 : virtual public L { /* ... */ };
class D : public B1, public B2 { /* ... */ }; // valid
Do we have side effect when we use virtual public when we don't use it for single inheritance. For example, is
class L { /* ... */ }; // indirect base class
class B1 : virtual public L { /* ... */ };
class D : public B1 { /* ... */ }; // valid
the same as
class L { /* ... */ }; // indirect base class
class B1 : public L { /* ... */ };
class D : public B1 { /* ... */ }; // valid
? I mean, is it just safe to make the parent class as virtual for all possible cases?
It's just as safe to make the parent class virtual "just in case." The standard doesn't specify how virtual inheritance will be implemented, but there will probably be a slight performance hit. Unless you're writing something performance-critical, you shouldn't need to worry about it.
http://www.phpcompiler.org/articles/virtualinheritance.html
classes needed to be extended with one or more virtual pointers, and a simple attribute lookup in an object now needs two indirections through the virtual table
Not unlike virtual functions.
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