Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ g++;错误:应为主表达式_C++_Templates_C++03 - Fatal编程技术网

C++ g++;错误:应为主表达式

C++ g++;错误:应为主表达式,c++,templates,c++03,C++,Templates,C++03,看看这个例子: 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> stru

看看这个例子:

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();
}
结构父级 { 模板 内联静态t get_t(); }; 结构子级:公共父级 { 模板 内联静态t get_t() { 返回t(-1); } }; 模板 结构调用 { 内联静态int get_值() { 返回t::get_t(); } }; typedef调用测试; 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
在静态成员函数“static int call::get_value()”中:
错误:“int”之前应为主表达式
错误:应为“;”在“int”之前
错误:在“>”标记之前应为非限定id
<> >用Visual C++ 2008和英特尔C++编译代码时,编译时无问题。
该错误是什么意思?

您需要模板限定符:

return t::template get_t<int>();
returnt::template get_t();
见:


您需要模板限定符:

return t::template get_t<int>();
returnt::template get_t();
见:

只需添加

模板

关键词:

template <typename t>
struct call
{
    inline static int get_value()
    {
        return t::template get_t<int>();
    }
};
模板
结构调用
{
内联静态int get_值()
{
返回t::模板get_t();
}
};
只需添加

模板

关键词:

template <typename t>
struct call
{
    inline static int get_value()
    {
        return t::template get_t<int>();
    }
};
模板
结构调用
{
内联静态int get_值()
{
返回t::模板get_t();
}
};