当我在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应用程序编写代码时,我从未见过这样的警告消息.
我是否必须认真对待这件事?
解决方法:
你所拥有的是通过大括号缩写称为聚合初始化,你完全没问题,代码符合标准.
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.
查看更多详情here和here.
标签:c-2,arrays,android,warnings,braces
来源: https://codeday.me/bug/20190609/1203114.html