【问题标题】:C++ template parse error [duplicate]C ++模板解析错误[重复]
【发布时间】:2013-01-31 12:11:34
【问题描述】:

可能重复:
Where and why do I have to put the “template” and “typename” keywords?

我在A 类中有一个静态模板方法test,它采用单个bool 模板参数。当我尝试这样调用函数时:

x = A::test<true>(...);

解析器抱怨它将&lt; 视为小于运算符。我如何告诉编译器这是一个模板实例化而不是一个小于运算符?

【问题讨论】:

  • A是模板参数吗?

标签: c++ parsing templates parse-error


【解决方案1】:

【讨论】:

  • 只有当A 是模板参数(或它的依赖类型)时才需要。
【解决方案2】:

template 关键字消除了歧义。

x = A::template test<true>(...);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2021-12-27
    • 2017-05-12
    • 2016-04-21
    • 2010-11-24
    • 2016-12-25
    • 2017-02-19
    相关资源
    最近更新 更多