I have a problem with the following situation:
template<class T>
class A {
public: virtual int f() { return 1; }
};
class BaseA : public A<BaseA> {};
class DerivedA : public BaseA, public A<DerivedA> {};
and when I do:
BaseA* b1 = new DerivedA;
b1->f();
it calls A<BaseA>::f() instead of A<DerivedA>::f() and I don't know how to fix it.
Additional info from the OP: this is a homework problem where class
Acan be freely changed, but classesBaseAandDerivedAcannot be changed.Then the following is one solution, based on dominance in a virtual inheritance hierarhcy: