mercredi 19 juin 2019

Pattern to access differently named member functions of derived classes

So I have the following class hierarchy and both the derived classes have differently named member functions which I want to access in a common manner.

class T {}
class T1::T {
    int getIntT1() {}
}
class T2::T {
    int getIntT2() {}
}

I created a template to access these member functions.

template<typename T, int (T::*f)()>
int getInt(T t) {}

I can't change the class definitions, so is there any other way to do this?

Aucun commentaire:

Enregistrer un commentaire