开发者

c++ template syntax

开发者 https://www.devze.com 2023-01-14 23:33 出处:网络
How do I fix this syntax error? str开发者_如何学Cuct A { template < typename T > void f () {}

How do I fix this syntax error?

str开发者_如何学Cuct 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 ();
}


U is a dependent type so you need to specify that f is a template member:

U::template f<C>();

This is still invalid when U is A, though, as f is not a static member of A.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号