Is this a list initialization or a value initialization?

Viewed 83
2 Answers

Is this List Initialization or Value Initialization?

It is direct-list-initialization

T object { arg1, arg2, ... }; (1)

direct-list-initialization (both explicit and non-explicit constructors are considered)

  1. initialization of a named variable with a braced-init-list (that is, a possibly empty brace-enclosed list of expressions or nested braced-init-lists)

and the effect on T is value-initialization

Explanation

The effects of list initialization of an object of type T are:

[...]

  • Otherwise, if the braced-init-list has no elements, T is value-initialized.

And now for the value-initialization of integer you get zero-initialized.

Explanation

Value initialization is performed in these situations:

[...]

  1. otherwise, the object is zero-initialized.
Related