113. Multiple Inheritance Ambiguity

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:

  • PowerControl
    Provides a function:
    • enable()
  • InterruptControl
    Provides a function:
    • enable()

A driver class:

  • SpiDriver inherits publicly from both 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:

  • The multiple inheritance ambiguity is resolved correctly
  • The appropriate base class enable() function is called based on input
  • The output clearly indicates which capability is being enabled
  • The class hierarchy remains unchanged

 

Rules (Strict)

You must follow all rules below:

  • Do NOT modify base class implementations
  • Do NOT rename any functions
  • Do NOT remove multiple inheritance
  • Do NOT use:
    • Virtual functions
    • Dynamic memory allocation
    • Composition
  • You MAY use scope resolution to disambiguate function calls
  • Use only standard input and output
  • Output text and order must match exactly

 

Input

One integer value:

  • mode

Where:

  • 0 → Enable power control
  • 1 → Enable interrupt control

Program Flow (Mandatory Order)

  1. Read integer mode
  2. Create a SpiDriver object
  3. If mode == 0:
    • Enable power control
  4. If mode == 1:
    • Enable interrupt control

Output

  • If mode == 0:

    Power enabled 
  • If mode == 1:

    Interrupt enabled 

 

Example 1

Input:

0

Output:

Power enabled 

 

Example 2

Input:

1

Output:

Interrupt enabled

 

 

 

Loading...

Input

0

Expected Output

Power enabled