I have a multiple inheritance scenario without virtual base classes like this:
Ta Tb
| |
B C
\ /
A
Ta and Tb are two different template classes that both declare a virtual function named f(). I want to override the two function in the A scope, because I have to interact with both B and C data in these methods. But I don't know how to do this.
class Tb {
protected:
virtual void f() {};
public:
void call() {
this->f();
};
};
class Tc {
protected:
virtual void f() {};
public:
void call() {
this->f();
};
};
class B : public Tb {
public:
void doSomething() {};
};
class C : public Tc {
private:
int c;
public:
void inc() { c++; };
};
class A : public B, public C {
protected:
void f() { // this is legal but I don't want to override both with the same definition.
// code here
}
// if Tb::f() is called then i want to call C::inc()
// if Tc::f() is called then i want to call B::doSomething()
public:
void call() {
B::call();
C::call();
};
};
Is there a syntax to override both the methods with different definitions or do I have to define these in B and C?
Thanks
Edit: My problem is not that a cant call Tb::f() or Tc::f(), but that i want to define two different behavior if Tb::f() or Tc::f() is called. These methods are called by Tb and Tc itself in its own public methods. Modified the example so maybe is more clear what i want to do...