Abgeleitete Klasse, die mehrere Schnittstellen mit einer gemeinsamen Funktionssignatur implementiert

Beim Versuch, meinen Code zu kompilieren, wird ein Kompilierungsfehler angezeigt. Der Fehler ist folgender:

multi.cc: In function ‘int main()’:
multi.cc:35: error: cannot declare variable ‘mdc’ to be of abstract type ‘MostDerivedClass’
multi.cc:27: note:   because the following virtual functions are pure within ‘MostDerivedClass’:
multi.cc:13: note:  virtual int Interface2::common_func()
multi.cc:36: error: request for member ‘common_func’ is ambiguous
multi.cc:13: error: candidates are: virtual int Interface2::common_func()
multi.cc:21: error:                 virtual int InterimClass::common_func()

Und hier ist mein Code:

class Interface1 {
public:
    virtual int common_func() = 0;
    virtual ~Interface1() {};
};

class Interface2 {
public:
    virtual int common_func() = 0;
    virtual int new_func() = 0;
    virtual ~Interface2() {};
};


class InterimClass : public Interface1 {
public:
    virtual int common_func() {
        return 10;
    }
};


class MostDerivedClass : public InterimClass, public Interface2 {
public:
    virtual int new_func() {
        return 20;
    }   
};

int main() {
    MostDerivedClass mdc;
    int x = mdc.common_func();
    cout << "The value = " << x << endl;    

    Interface2 &subset_of_funcs = dynamic_cast<Interface2 &>(mdc);
    x = subset_of_funcs.common_func();
}

Meine Fragen:

Wie kann ich dem Compiler mitteilen, dass common_func () bereits von der InterimClass implementiert ist, die eine Basisklasse von MostDerivedClass ist?

Gibt es eine andere Möglichkeit, mein Problem zu beheben? Was ich wirklich gerne tun würde, ist in der Lage zu sein, common_func von Interface2 aufzurufen. Ich arbeite mit einem Legacy-Code mit einer Vielzahl von Methoden in Interface1. In meinem neuen Code möchte ich nur einen kleinen Satz dieser Interface1-Funktionen aufrufen sowie einige, die ich hinzufügen muss.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage