Variadic Templates - Klassen-Parameter-Packs und Methoden
Verfasst: 31.01.2012, 19:01
Hallo allerseits!
Ich hab eine kleine Frage für die C++11-Cracks unter euch. Ich bin mit einigen neuen Sprachfeatures leider noch nicht so ganz firm und bevor ich jetzt ewig rumbastel... Ich möchte im Wesentlichen das Parameter-Pack einer Klasse innerhalb einer ihrer Methode abrollen.
Etwas Beispiel-Code:
Wirft bei mir (GCC 4.6) folgende Fehlermeldung:
Ich hab eine kleine Frage für die C++11-Cracks unter euch. Ich bin mit einigen neuen Sprachfeatures leider noch nicht so ganz firm und bevor ich jetzt ewig rumbastel... Ich möchte im Wesentlichen das Parameter-Pack einer Klasse innerhalb einer ihrer Methode abrollen.
Etwas Beispiel-Code:
Code: Alles auswählen
struct base1
{
void base_test() { std::cout << "base 1" << std::endl; }
};
struct base2
{
void base_test() { std::cout << "base 2" << std::endl; }
};
struct base3
{
void base_test() { std::cout << "base 3" << std::endl; }
};
template<typename ...Args>
struct derived : public Args...
{
void test() {}
template<typename T, typename ...TestArgs>
void test()
{
T::base_test();
test<TestArgs...>();
}
void my_test()
{
test<Args...>();
}
};
Scheint so, als wenn der Base Case nicht akzeptiert wird. Ideen?ssa/main.cpp: In member function 'void derived<Args>::test() [with T = base3, TestArgs = {}, Args = {base1, base2, base3}]':
ssa/main.cpp:74:9: recursively instantiated from 'void derived<Args>::test() [with T = base2, TestArgs = {base3}, Args = {base1, base2, base3}]'
ssa/main.cpp:74:9: instantiated from 'void derived<Args>::test() [with T = base1, TestArgs = {base2, base3}, Args = {base1, base2, base3}]'
ssa/main.cpp:79:9: instantiated from 'void derived<Args>::my_test() [with Args = {base1, base2, base3}]'
ssa/main.cpp:97:16: instantiated from here
ssa/main.cpp:74:9: error: no matching function for call to 'derived<base1, base2, base3>::test()'
ssa/main.cpp:74:9: note: candidate is:
ssa/main.cpp:70:19: note: template<class T, class ... TestArgs> void derived::test() [with T = T, TestArgs = {TestArgs ...}, Args = {base1, base2, base3}]