It depends on the implementation, but typically virtual inheritance will need:
- an extra pointer (or offset) for each virtual base class: the adjustment to convert (for example)
B*
toA*
will depend on which other subobjects in the same object also derive virtually fromA
. I think this can be stored in the vtable, rather than the object itself, so that the overhead could be per-class rather than per-object. - extra logic in the constructor and destructor, to determine whether or not the virtual base object needs initialising/destroying at that point.
- extra work for some pointer conversions, reading the stored pointer/offset rather than applying a compile-time constant.
For memory usage, you can measure the per-object overhead in your implementation by printing sizeof (MyB)
. Any per-class overhead will probably be negligible, unless you have a huge number of classes.