【发布时间】:2016-09-09 07:52:36
【问题描述】:
使用 GCC 5.1.0 (tdm64-1) 编译以下代码时出现奇怪的编译错误
template <class T>
struct test {
template <class X>
bool func();
};
template <class X, class Y>
bool testfunc(X x, Y y)
{
test<Y> s;
if (s.func<X>()) // <-- parse error here
return false;
}
void func2()
{
testfunc( double(), long() );
}
错误是
testX.cpp: In function 'bool testfunc(X, Y)':
testX.cpp:12:15: error: expected primary-expression before '>' token
if (s.func<X>())
^
testX.cpp:12:17: error: expected primary-expression before ')' token
if (s.func<X>())
请注意,该错误仅出现在 Y 为模板参数的版本中。当我删除 Y 模板参数并使用已知类型(例如 test
那么这里出了什么问题?
【问题讨论】:
标签: c++ templates compiler-errors