Multiple Inheritance Ambiguity

#include <iostream>
using namespace std;

class PowerControl {
public:
    void enable() {
        cout << "Power enabled" << endl;
    }
};

class InterruptControl {
public:
    void enable() {
        cout << "Interrupt enabled" << endl;
    }
};

// Multiple inheritance
class SpiDriver : public PowerControl, public InterruptControl {
};

int main() {
    int mode;
    cin >> mode;

    SpiDriver spi;

    // Fix ambiguity and call correct enable() based on mode
    (mode == 0) ? spi.PowerControl::enable() : spi.InterruptControl::enable();

    return 0;
}
Upvote
Downvote
Loading...

Input

0

Expected Output

Power enabled