I have a class A that stores some state dependend on its template parameter and provides access methods for it. In my framework I need to enable derived classes B to add more of those state based classes to the hirarchy, so that they can be accessed from the derived class with a single API. The user should not notice that the state class has been splittet into multiple ones. Thats the schema I came up with:
#include <iostream>
#include <type_traits>
using namespace std;
template<typename T1>
struct Test {
template<typename T2>
typename enable_if<is_same<T1, T2>::value, void>::type myFunction() {};
};
struct A : public Test<int> {};
struct B : public A, public Test<char> {};
int main() {
B b;
b.myFunction<int>();
return 0;
}
but unfortunately it does not work, the compiler still finds both functions and reports them to be ambiguous.
Any idea how this could be achieved?