c++ template syntax

Tho*_*mas 3 c++ templates

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)

CB *_*ley 9

U 是一种依赖类型,因此您需要指定它 f是模板成员:

U::template f<C>();
Run Code Online (Sandbox Code Playgroud)

这仍然是无效的时候UA,虽然,因为f不是一个static成员A.