【发布时间】:2017-10-26 00:13:23
【问题描述】:
与
template <typename T>
class Foo {
public:
template <int x>
void bar () {}
};
以下编译:
void fooBar ()
{
Foo<int> f;
f.bar<1>();
}
但以下没有(在 gcc 5.4.0 中使用 -std=c++14 的“错误:预期的主表达式在 ')' 标记之前”)。
template <typename T>
void fooBar ()
{
Foo<T> f;
f.bar<1>();
}
如果我尝试显式调用第二个版本,例如
fooBar<int>();
然后gcc另外抱怨
"invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'".
第二个版本无效有什么原因吗?为什么 gcc 将 '
【问题讨论】:
-
foo<>();的功能是什么?它存在于哪里? -
@alhadhrami 对不起 - 应该读过 fooBar。在编辑中更正。