看看这个样本:
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 ++编译代码时,它编译没有问题。
该错误意味着什么?
答案 0 :(得分:3)
您需要模板限定符:
return t::template get_t<int>();
请参阅:
Where and why do I have to put the "template" and "typename" keywords?
答案 1 :(得分:0)
只需添加
模板
关键字:
template <typename t>
struct call
{
inline static int get_value()
{
return t::template get_t<int>();
}
};