Cześć,
na początek fragment kodu:
class Foo {
public:
template<typename Type>
Type get();
private:
int value = 10;
};
template<>
int Foo::get(){
return value;
}
template<>
string Foo::get(){
return to_string(value);
}
//**************************************
class Bar {
public:
template<typename Type>
Type get();
private:
int value = 15;
};
template<>
int Bar::get(){
return value;
}
template<>
string Bar::get(){
return to_string(value);
}
//**************************************
class Elo {
public:
template<typename Type>
Type get();
private:
Foo foo;
Bar bar;
};
template<>
int Elo::get(){
return foo.get<int>();
}
template<>
string Elo::get(){
return foo.get<string>();
}
template<>
int Elo::get(){
return bar.get<int>();
}
template<>
string Elo::get(){
return bar.get<string>();
}
A teraz pytanie, w jaki sposób mogę tak napisać specjalizację szablonowej metody get() w klasie Elo, aby w zależności od podanych parametrów wywołała się metoda get() z klasy Bar lub klasy Foo?
Czyli coś takiego, by mnie interesowało:
elo.get<string, Bar>();
elo.get<int, Foo>();