compiler-errors - g++ 错误需要一个类型,得到 ‘classname’

标签 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 一切正常。我做错了什么?

最佳答案

不幸的是,<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/

相关文章:

c++ - 模板类中的c++运算符重载Im正在尝试构建重载<<以打印树

c++ - "Undefined reference to"链接目标文件时出错

c++ - 如何让 g++ 列出所有 #included 文件的路径

c++ - '#if _LFS64_LARGEFILE-0' 对 CPP 意味着什么?

visual-studio-2015 - 为什么没有管理员权限就无法编译Visual Studio

c++ - 无法同时编译ncurses和字符串

Java- 试图分配较弱的类权限

C++非整数模板Const初始化预期在ClassName之前的init-declarator

c++ - Clang 和 GCC 在强制转换 C++17 中的非类型模板参数的自动说明符中存在分歧

xcode - 默认情况下,对于iOS4项目的XCode中已弃用的代码是否存在编译警告或错误?