1

我对这个模板中最新的 cygwin(1.7.24 64bit, GCC 4.8.1-3 64bit) 编译器有疑问:

template <typename _T, int _N>
vector<_T> makeVector(const _T(&data)[_N]) {
    return vector<_T> (data, data + _N);
}

编译器说:

error: expected '>' before numeric constant

但我很确定它是有效的代码,因为我过去在 Windows 上使用 TDM-GCC 和在学校测试 Linux 上构建过它。

如果您知道如何解决这个问题,请告诉我,谢谢。

4

2 回答 2

1

我可能无法重现该问题,因为我没有 Cygwin 或运行 Cygwin 的系统。我会尝试将上面的代码替换为

#include <vector>
template <typename T, std::size_t N>
std::vector<T> makeVector(T (&array)[N]) {
    return std::vector<T>(array, array + N);
}

...看看问题是否仍然存在。顺便说一句,注释中引用的代码为我编译(嗯,我需要删除源文件中不需要的包含保护,仅在标头中需要)。

于 2013-08-25T00:40:11.103 回答
1

I found that _N cannot be used by us in cygwin because _N seems to already be defined as a numeric constant. Just replace N by other names such as N.

于 2017-11-23T19:13:41.880 回答