![](/img/trans.png)
[英]g++ (freebsd) error: expected primary-expression before '{' token
[英]g++ error: expected primary-expression
看这个例子:
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();
}
该代码编译时出现以下错误:
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 ++编译代码时,它可以毫无问题地进行编译。
该错误是什么意思?
只需添加
模板
关键词:
template <typename t>
struct call
{
inline static int get_value()
{
return t::template get_t<int>();
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.