What is the price of virtual inheritance in terms of the time required to access members of the derived class itself?
one shift-search and addition (2 commands and memory fetch)
In particular, if there is a non-zero price, does it apply only to members that are inherited in more than one way or to other members?
Yes, and even then not always. If the compiler has enough information to prove that access does not have to be indirect, it can shorten the search at compile time.
Perhaps it would be good to clarify when this will be so. - Nicol Bolas
Well said sir.
Here is an example to demonstrate this. Compile with the -O2 and -S options to see the optimization in action.
#include <memory>
source share