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
struct MecEngineer {
void buildRobot() { /* .... */ }
};
struct EleEngineer {
void buildRobot() { /* .... */ }
};
struct RoboticsEngineer : MecEngineer, EleEngineer {
};
Now when you do,
robEngObject -> buildRobot() ;
Such a call cannot be resolved and is ambiguous because both the sub-objects has a member function with same signature and compiler doesn't know which one to call. In such a situation, you need to explicitly mention it using ::
operator or by using static_cast
.
static_cast (robEngObject) -> buildRobot() ;