In embedded firmware development, drivers often support multiple independent capabilities such as power management and interrupt handling.
One common approach is to use multiple inheritance to compose these capabilities.
However, when multiple base classes expose functions with the same name, calling those functions from the derived class can lead to compile-time ambiguity.
This problem focuses on correctly resolving such ambiguity using standard C++ techniques that are safe and commonly used in firmware codebases.
Scenario
You are given two capability-style base classes:
enable()enable()A driver class:
PowerControl and InterruptControl.Because both base classes define a function named enable(), calling enable() directly on a SpiDriver object is ambiguous and will not compile.
Objective
Modify the program so that:
enable() function is called based on input
Rules (Strict)
You must follow all rules below:
Input
One integer value:
modeWhere:
0 → Enable power control1 → Enable interrupt controlProgram Flow (Mandatory Order)
modeSpiDriver objectmode == 0:mode == 1:Output
If mode == 0:
Power enabled If mode == 1:
Interrupt enabled
Example 1
Input:
0Output:
Power enabled
Example 2
Input:
1Output:
Interrupt enabled
Input
0
Expected Output
Power enabled