Why can we initialize an array with just an initializer list

In the following example

#include <iostream>

int a[][2] = {{1, 4}, {2, 6}};
int b[][3] = a; // error: array initializer must be an initializer list

      

DEMO

Why can't we initialize the array in some way instead initializer-list

? I tried searching for it in N4296::8.5.4 [dcl.init.list]

, but it doesn't seem to have anything suitable.

+3


source to share


1 answer


This question looks like the opposite, as does the error message. It has always been the case that you cannot initialize an array from the name of another array. Initializer lists are irrelevant to this.



[C++11: 8.5/16]:

The semantics of initializers are as follows. The destination type is the type of the initialized object or reference, and the source type is the type of the initializer expression. If the initializer is not a single (possibly parenthesized) expression, the source type is undefined.

  • If the initializer is a (not parenthesized) bit-init-list, the object or reference is initialized with a list (8.5.4).
  • If the target type is a reference type, see 8.5.3.
  • If the destination type is a character array char16_t

    , array , array , char32_t

    or array wchar_t

    and the initializer is a string literal, see 8.5.2.
  • If an initializer ()

    , the object is value-initialized.
  • Otherwise, if the destination type is an array, the program is ill-formed.
  • [..]
+3


source







All Articles