1

I have a function declaration as follows

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

If I call the function like this everything is 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

Why does the first code work but not the second one?

scohe001
  • 15,110
  • 2
  • 31
  • 51
Lars
  • 1,750
  • 2
  • 17
  • 26

1 Answers1

3

Your function expects an array object, not an initialization list for such an object.

Alex
  • 111
  • 3