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