I am trying to figure out where to use template and typename , and I ran into a problem that I cannot get around. I have a template function f<T> that uses the type passed to it (which will be a class) to call the template member function .f<T> . I think my use of typename in the body of the function is correct, however I continue to get the following error:
source.cpp: In the function 'void f()' :
source.cpp: 11:19: error: not pattern 'f' used as pattern
source.cpp: 11:19: note: use 'typename T::C::template f' to indicate that it is a template
struct A { struct C { template <typename T> void f() {} }; }; template <typename T> void f() { typename T::C::f<int>(); } int main() { f<A>(); }
Note that with the last error, it is recommended to use 'typename T::C::template f' . So I made the following change:
I did as he said, but then I got the following error line:
error: no class template named 'f' in 'struct A::C'
I believe that this error is incorrect in that there actually exists a public template function named f in struct A::C What can i do wrong here?
source share