Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Commonmark migration
Source Link

Paragraph 17 of [dcl.init] specifies all possible initializers for arrays.

17 The semantics of initializers are as follows. The destination type is the type of the object or reference being initialized 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 not defined.

(17.1) If the initializer is a (non-parenthesized) braced-init-list or is = braced-init-list, the object or reference is list-initialized.

(17.2) If the destination type is a reference type, see [dcl.init.ref].

(17.3) If the destination type is an array of characters, an array of char16_­t, an array of char32_­t, or an array of wchar_­t, and the initializer is a string literal, see [dcl.init.string].

(17.4) If the initializer is (), the object is value-initialized.

(17.5) Otherwise, if the destination type is an array, the program is ill-formed.

(17.2) is not applicable to arrays, so the options are:

  1. Default-initialization ([dcl.init]/12): int x[3];
  2. Value-initialization ([dcl.init]/17.4): int* x = new int[3]();
  3. List-initialization ([dcl.init]/17.1): int x[] = {1, 2, 3}; or int x[] {1, 2, 3};
  4. Initialization with a string literal ([dcl.init]/17.3): char x[] = "text";

Paragraph 17 of [dcl.init] specifies all possible initializers for arrays.

17 The semantics of initializers are as follows. The destination type is the type of the object or reference being initialized 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 not defined.

(17.1) If the initializer is a (non-parenthesized) braced-init-list or is = braced-init-list, the object or reference is list-initialized.

(17.2) If the destination type is a reference type, see [dcl.init.ref].

(17.3) If the destination type is an array of characters, an array of char16_­t, an array of char32_­t, or an array of wchar_­t, and the initializer is a string literal, see [dcl.init.string].

(17.4) If the initializer is (), the object is value-initialized.

(17.5) Otherwise, if the destination type is an array, the program is ill-formed.

(17.2) is not applicable to arrays, so the options are:

  1. Default-initialization ([dcl.init]/12): int x[3];
  2. Value-initialization ([dcl.init]/17.4): int* x = new int[3]();
  3. List-initialization ([dcl.init]/17.1): int x[] = {1, 2, 3}; or int x[] {1, 2, 3};
  4. Initialization with a string literal ([dcl.init]/17.3): char x[] = "text";

Paragraph 17 of [dcl.init] specifies all possible initializers for arrays.

17 The semantics of initializers are as follows. The destination type is the type of the object or reference being initialized 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 not defined.

(17.1) If the initializer is a (non-parenthesized) braced-init-list or is = braced-init-list, the object or reference is list-initialized.

(17.2) If the destination type is a reference type, see [dcl.init.ref].

(17.3) If the destination type is an array of characters, an array of char16_­t, an array of char32_­t, or an array of wchar_­t, and the initializer is a string literal, see [dcl.init.string].

(17.4) If the initializer is (), the object is value-initialized.

(17.5) Otherwise, if the destination type is an array, the program is ill-formed.

(17.2) is not applicable to arrays, so the options are:

  1. Default-initialization ([dcl.init]/12): int x[3];
  2. Value-initialization ([dcl.init]/17.4): int* x = new int[3]();
  3. List-initialization ([dcl.init]/17.1): int x[] = {1, 2, 3}; or int x[] {1, 2, 3};
  4. Initialization with a string literal ([dcl.init]/17.3): char x[] = "text";
Source Link
Anton
  • 3.2k
  • 16
  • 13

Paragraph 17 of [dcl.init] specifies all possible initializers for arrays.

17 The semantics of initializers are as follows. The destination type is the type of the object or reference being initialized 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 not defined.

(17.1) If the initializer is a (non-parenthesized) braced-init-list or is = braced-init-list, the object or reference is list-initialized.

(17.2) If the destination type is a reference type, see [dcl.init.ref].

(17.3) If the destination type is an array of characters, an array of char16_­t, an array of char32_­t, or an array of wchar_­t, and the initializer is a string literal, see [dcl.init.string].

(17.4) If the initializer is (), the object is value-initialized.

(17.5) Otherwise, if the destination type is an array, the program is ill-formed.

(17.2) is not applicable to arrays, so the options are:

  1. Default-initialization ([dcl.init]/12): int x[3];
  2. Value-initialization ([dcl.init]/17.4): int* x = new int[3]();
  3. List-initialization ([dcl.init]/17.1): int x[] = {1, 2, 3}; or int x[] {1, 2, 3};
  4. Initialization with a string literal ([dcl.init]/17.3): char x[] = "text";
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /