C ++ 11:正确的std ::数组初始化? [英] C++11: Correct std::array initialization?
本文介绍了C ++ 11:正确的std ::数组初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我初始化一个std ::排列如下,编译器给了我一个警告有关丢失括号
If I initialize a std::array as follows, the compiler gives me a warning about missing braces
std::array<int, 4> a = {1, 2, 3, 4};
这解决了这个问题:
std::array<int, 4> a = {{1, 2, 3, 4}};
这是警告消息:
missing braces around initializer for 'std::array<int, 4u>::value_type [4] {aka int [4]}' [-Wmissing-braces]
这只是在我的版本的GCC的bug,或者是它故意做了什么?如果是这样,为什么?
Is this just a bug in my version of gcc, or is it done intentionally? If so, why?
推荐答案
这是裸实施的std ::阵列
的:
template<typename T, std::size_t N>
struct array {
T __array_impl[N];
};
这是一个聚合结构,其唯一的数据成员是一个传统的阵列,使得内部 {}
用于初始化内部阵列
底架省音被允许在某些情况下与骨料初始化等只有一个支架可以在这种情况下使用。在这里看到: C ++数组矢量
Brace elision is allowed in certain cases with aggregate initialization (but usually not recommended) and so only one brace can be used in this case. See here: C++ vector of arrays
这篇关于C ++ 11:正确的std ::数组初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文