简体   繁体   English

无法将std数组初始化为std向量

[英]Cant initialize a std array into a std vector

Not an actual problem but rather a fashion crisis.. 不是实际问题,而是时尚危机..

 vector<array<unsigned int, 3>> tri;
 tri.push_back(array<unsigned int, 3> {0, 0, 0});

gives me a syntax error. 给我一个语法错误。 Is there any way to initialize a std array with values into a vector in one line? 有没有办法初始化一个std数组与值在一行中的向量?

The first rule of std::array is: when in doubt, add more braces. std::array的第一条规则是:如有疑问,请添加更多大括号。 That's because you're actually initializing the raw array subobject of the std::array . 那是因为你实际上正在初始化std::array的原始数组子对象。

tri.push_back(array<unsigned int, 3> {{0, 0, 0}});

Both GCC and Clang accept this statement. 海湾合作委员会和克朗都接受这一声明。

vs10 still wont accept it :/ vs10仍然不接受它:/

And this is why it's important to always provide complete information in your questions. 这就是为什么始终在您的问题中提供完整信息非常重要的原因。

Visual Studio 2010 does not implement uniform initialization (and that is uniform initialization, not merely aggregate initialization). Visual Studio 2010不实现统一初始化(这是统一初始化,而不仅仅是聚合初始化)。 It's not a C++11-compliant compiler; 它不是符合C ++ 11标准的编译器; it just has a few C++11 features. 它只是有一些C ++ 11功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM