【发布时间】:2023-09-07 23:24:02
【问题描述】:
我有错误“'int'之前的预期主表达式”和“预期';'在这段代码中的“int”之前,有人知道为什么吗?
struct cpu
{
template<class T> static void fce() {}
};
template<class _cpu>
struct S
{
void fce()
{
_cpu::fce<int>(); //error: expected primary-expression before 'int'
//error: expected ';' before 'int'
}
};
int main()
{
S<cpu> s;
s.fce();
}
【问题讨论】:
-
试试 _cpu::template fce
();将 fce 视为依赖模板名称。 -
@0x499602D2 更好的回答哈哈
标签: c++ templates compiler-errors