android - 多维数组缺少大括号

标签 android c++ arrays warnings braces

当我在 Visual Studio 中为 Android 共享库构建项目时,我在下面收到一条警告消息。

warning : suggest braces around initialization of subobject
[-Wmissing-braces]

此消息指示仅使用一对大括号的数组初始化语句。

int myArray[ROW][COL] = { 1, 2, 3, 4, 5, 6, ..., 451, 452, 453 };

我不能写两对的原因是将来有可能改变 ROW 和 COL 的大小。

它工作正常,但我不确定是否可以这样离开项目,因为我在为仅限 Windows 的应用程序编写代码时从未见过这样的警告消息。

我必须认真对待这件事吗?

最佳答案

您所拥有的称为通过大括号省略的聚合初始化,您完全没问题,代码符合标准。

来自 cppreference.com :

If the aggregate initialization uses the form with the equal sign (T a = {args..}), (until C++14) the braces around the nested initializer lists may be elided (omitted), in which case as many initializer clauses as necessary are used to initialize every member or element of the corresponding subaggregate, and the subsequent initializer clauses are used to initialize the following members of the object. However, if the object has a sub-aggregate without any members (an empty struct, or a struct holding only static members), brace elision is not allowed, and an empty nested list {} must be used.

查看更多详情 herehere .

关于android - 多维数组缺少大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32697432/

相关文章:

android - 如何在 Android 中为 AutoCompleteTextView 设置多次点击监听器?

java - OpenCV VideoWriter fourCC Android

c++ - Visual C++ 类库

javascript - 根据嵌套对象数组中的动态键过滤数组

android - AppWidgetProvider的onDisabled()和onDeleted()的区别

java - finish()后刷新文本EditText

c++ - 如何为 std::sort() 编写用户定义的比较

c++ - OpenMP 循环并行化

php - for 循环中包含 foreach 循环? PHP

c++ - 将 long 复制到 unsigned char 数组的后半部分