Zeiger auf static-methode mit Template
-
Hallo,
was stimmt hier nicht?
struct S { template<class T> static void foo() {} }; template<class T> void Funktion() { void(*pf)() = &T::foo<int>; pf(); } int main() { Funktion<S>(); }
Wenn ich S::foo() nicht als template-Funktion habe, funktionierts.
Wenn foo() eine freie Funktion ist, also kein static-Member von S, dann funktionierts auch.
Nur in dieser Kombination nicht
-
Du musst dem Compiler sagen, dass T::foo ein template sein soll, sonst interpretiert er die <> falsch.
void (*pf)() = T::template foo<int>;
-
Ahja, funktioniert.
Danke.
-
Und wieder was gelernt ohne was gefragt zu haben.