[英]Could not convert from brace-enclosed initializer list to std::vector
I saw a lot of similar questions, but I don't think I saw quite the same one. 我看到了很多类似的问题,但我认为我没有看到相同的问题。 It's pretty basic. 这很基础。 Some code from my lecturer is failing to compile, and I distilled the problem to this test case: 我的讲师的一些代码无法编译,我将问题提炼到这个测试用例:
void foo(vector<int> v) {
}
void fooUsage() {
foo({0, 1, 2});
}
This fails with: 这失败了:
could not convert '{0, 1, 2}' from '<brace-enclosed initializer list>' to 'std::vector<int>
Note: It works on GCC 5.0.0 20141228 but fails on my GCC 4.7.1 (tdm-1). 注意:它适用于GCC 5.0.0 20141228但在我的GCC 4.7.1(tdm-1)上失败。
Sorry if this is too basic but I don't know C++11 very well. 对不起,如果这太基础但我不太了解C ++ 11。
It turns out I only needed to add -std=c++11
to the gcc command line. 事实证明我只需要将-std=c++11
添加到gcc命令行。
Note: I was mistakenly thinking that this is on by default, since I was also getting some warnings like this: 注意:我错误地认为这是默认开启的,因为我也收到了一些警告:
extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
See how it says "enabled by default"? 看看它是如何“默认启用”的? That's what was misleading me. 这就是误导我的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.