g ++错误预期类型,得到'classname'

时间:2014-10-20 15:30:01

标签: compiler-errors g++

在g ++中使用以下代码:

#include <iostream> 
#include <vector>
typedef std::vector<int> array;
typedef std::vector<array *> list;


struct time{
    int beg;
    int end;
    time(){
    beg=0;
    end=0;
    }
};

void explore(int v, std::vector<bool> & visited, list & l, std::vector<time> & times);

int main()
{
    return 0;
}

我收到了错误:

期待一种类型,得到'时间'

模板参数2无效

使用MSVC ++ 2013一切正常。我做错了什么?

1 个答案:

答案 0 :(得分:2)

不幸的是,g ++提供的<iostream>递归地包括C <time.h> header,它声明了函数time_t time(time_t*)。在解析模板实例化参数时,函数标识符优先于类型名称,即使相应的模板参数是类型也是如此。

解决方法是编写std::vector<struct time>,但最好使用命名空间或使用C标准未使用的名称。

相关问题