【问题标题】:c++ template syntaxc++模板语法
【发布时间】:2011-04-07 00:12:55
【问题描述】:

如何解决这个语法错误?

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

【问题讨论】:

    标签: c++ templates


    【解决方案1】:

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

    U::template f<C>();
    

    UA 时,这仍然无效,因为f 不是staticA 成员。

    【讨论】:

    • 谢谢。我不知道那种语法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 2016-08-23
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多