[ACCEPTED]-Understanding virtual base classes and constructor calls-base-class
There is always just one constructor call, and 14 always of the actual, concrete class that 13 you instantiate. It is your responsibility to 12 endow each derived class with a constructor 11 which calls the base classes' constructors 10 if and as necessary, as you did in B
's constructor.
Update: Sorry 9 for missing your main point! Thanks to ildjarn.
However, your 8 B
inherits virtually from A
. According to the standard 7 (10.1.4 in the FIDS), "for each distinct 6 baseclass that is specified virtual, the 5 most derived object shall contain a single 4 base class subobject of that type". In your 3 case this means that when constructing the 2 base, your class F
immediately calls A
's default 1 constructor, not B
's.
Virtual base classes are always constructed by 1 the most derived class.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.