在 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 一切正常。我做错了什么?
最佳答案
不幸的是,<iostream>
g++ 提供的递归方式包括 C <time.h>
header ,它声明了函数 time_t time(time_t*)
。在解析模板实例化参数时,函数标识符优先于类型名称,即使相应的模板参数是类型也是如此。
解决方法是编写 std::vector<struct time>
,但最好使用命名空间或使用 C 标准未使用的名称。
关于compiler-errors - g++ 错误需要一个类型,得到 ‘classname’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26469386/