简体   繁体   English

数组初始化值太多

[英]Array too many initializer values

I have a function declaration as follows 我有一个函数声明如下

void set_values(float values[4][4]);

If I call the function like this everything is OK. 如果我这样调用这个函数一切都OK。

float values[4][4] = {
    { 1, 2, 3, 4 },
    { 1, 2, 3, 4 },
    { 1, 2, 3, 4 },
    { 1, 2, 3, 4 } 
};
mat1.set_values(values);

However i thought that I could take the array declared in the curly braces and pass it directly into the function like this: 但是我认为我可以采用花括号中声明的数组并将其直接传递给函数,如下所示:

    mat1.set_values({
        { 1, 2, 3, 4 },
        { 1, 2, 3, 4 },
        { 1, 2, 3, 4 },
        { 1, 2, 3, 4 } 
    });

But this gives me a compile error too many initializer values 但这给了我一个编译错误too many initializer values

Why does the first code work but not the second one? 为什么第一个代码可以工作而不是第二个代码呢?

您的函数需要一个数组对象,而不是这种对象的初始化列表。

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

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