I have two classes A and B, both defining method m(). Although the signatures of these methods are the same, they are two totally different methods with different meanings. In class C, I want to update both m(). Instead of writing a new m() in class C that fuses the two m() from A and B, I want to override them separately. See the following code:
class A { public: virtual void m() {cout << "MA" << endl;}};
class B { public: virtual void m() {cout << "MB" << endl;}};
class C : public A, public B {
public: virtual void m() update A {cout << "MA2" << endl;}};
public: virtual void m() update B {cout << "MB2" << endl;}};
}
void func(A* a) { a->m(); }
int main() {
C* c = new C();
c->B::m(); //print "MB2"
func(c); //print "MA2"
return 0;
}
I know that the update syntax is not supported in C++, but is there any workaround to simulate this in C++?