简体   繁体   English

c ++模板语法

[英]c++ template syntax

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 ();
}

U is a dependent type so you need to specify that f is a template member: U是依赖类型,因此您需要指定f是模板成员:

U::template f<C>();

This is still invalid when U is A , though, as f is not a static member of A . 但是,当UA ,这仍然无效,因为f不是Astatic成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM