Mixing virtual and non-virtual inheritance of a base class

后端 未结 3 1724
醉话见心
醉话见心 2020-12-09 08:51

This is the code:

struct Biology
{    
    Biology() { cout << \"Biology CTOR\" << endl; }
};

struct Human : Biology
{    
    Human() { cout &l         


        
3条回答
  •  抹茶落季
    2020-12-09 09:08

    Non virtual inheritance is an exclusive relationship, like membership. A class can be the non-virtual base class of one other class in a given complete object.

    This implies that a class can override virtual functions of a non virtual base class without causing conflicts or issues.

    A constructor can also initialize non virtual bases reliably.

    Only virtual bases can be direct base classes of many indirect bases of a complete object. Because a virtual base class can be shared, overriders can conflict.

    A constructor can try to initialize a virtual base subobject in the ctor-init-list, but if the class is further derived, that part of the ctor-init-list will be ignored.

提交回复
热议问题