How do I fix this syntax error?
struct A {
template < typename T >
void f () {}
};
template < typename C, typename U >
struct B {
void g () {
U::f < C > (); // expected primary-expression before »>« token
}
};
int main () {
B<int,A> b;
b.g ();
}
Run Code Online (Sandbox Code Playgroud)
U
是一种依赖类型,因此您需要指定它 f
是模板成员:
U::template f<C>();
Run Code Online (Sandbox Code Playgroud)
这仍然是无效的时候U
是A
,虽然,因为f
不是一个static
成员A
.