Multiple Inheritance from two derived classes

后端 未结 5 1300
清酒与你
清酒与你 2020-11-30 08:55

I have an abstract base class which acts as an interface.

I have two \"sets\" of derived classes, which implement half of the abstract class. ( one \"set\" defines t

5条回答
  •  暖寄归人
    2020-11-30 09:02

    It can be done, although it gives most the shivers.

    You need to use "virtual inheritance", the syntax for which is something like

    class AbsInit: public virtual AbsBase {...};
    class AbsWork: public virtual AbsBase {...};
    class NotAbsTotal: public AbsInit, public AbsWork {...};
    

    Then you have to specify which function you want to use:

    NotAbsTotal::work()
    {
        AbsInit::work_impl();
    }
    

    (UPDATED with correct syntax)

提交回复
热议问题