Multiple Inheritance, C++ and Same Method Signature in Multiple Super Classes

后端 未结 5 1346
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 18:42

I have no experience in C++, and I come from a Java background. Lately, I was asked in an interview on why Java would not allow multiple inheritence and the answer was pretty ea

5条回答
  •  有刺的猬
    2021-01-31 19:07

    The compiler will complain about this kind of situtation.

    In such a case c++ suggest to create an Interface with a "pure virtual" method buildRobot() function. MechanicalEngineer and EletricalEnginner will inherit the Interface and override the buildRoboot() function.

    When you create RoboticsEnginner object and call the buildRobot() function, the interface's function will be called.

提交回复
热议问题