g ++错误:预期的主表达式 [英] g++ error: expected primary-expression
本文介绍了g ++错误:预期的主表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查看此示例:
struct parent
{
template <typename t>
inline static t get_t();
};
struct child : public parent
{
template <typename t>
inline static t get_t()
{
return t(-1);
}
};
template <typename t>
struct call
{
inline static int get_value()
{
return t::get_t<int>();
}
};
typedef call< child > test;
int main()
{
int v = test::get_value();
}
代码编译时出现以下错误:
The code compile with the following error:
In static member function 'static int call<t>::get_value()':
error: expected primary-expression before 'int'
error: expected ';' before 'int'
error: expected unqualified-id before '>' token
当我用visual c ++ 2008和Intel C ++编译代码时,它编译没有问题。
When i compiled the code with visual c++ 2008 and Intel C++ it compiles without problem.
这个错误是什么意思?
推荐答案
您需要模板限定符:
return t::template get_t<int>();
请参阅:
这篇关于g ++错误:预期的主表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文