About multiple inheritance and defining virtual function

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: Моя проблема не в том, что не могу вызвать Tb :: f () или Tc :: f (), а в том, что я хочу определить два разных поведения, если вызывается Tb :: f () или Tc :: f (). Эти методы вызываются самими Tb и Tc в своих собственных общедоступных методах. Modified the example so maybe is more clear what i want to do...

13
задан Gianni Pisetta 6 May 2011 в 13:44
поделиться