c ++模板语法 [英] c++ template syntax

查看:109
本文介绍了c ++模板语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决此语法错误?

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 是一个依赖类型,因此您需要指定 f 是模板成员:

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

U::template f<C>();

U code> A ,但 f 不是 static A

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

这篇关于c ++模板语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆