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

后端 未结 5 1362
伪装坚强ぢ
伪装坚强ぢ 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:11

    It doesn't handle it. It's ambiguous. error C2385: ambiguous access of 'functionName'

    The compiler is smart enough to know that it shouldn't guess your meaning.
    For the program to compile, you need to tell the compiler that:
    A. You know it's a problematic issue.
    B. Tell it what exactly you mean.

    To do this, you need to explicitly tell the compiler which method you're asking for:

    RoboticsEngineer myRobot;
    myRobot.ElectricalEngineer::buildRobot();
    

提交回复
热议问题