Variable initalization with curly brackets

Viewed 73

Is the following syntax:

T t = {};

a zero-initalization or a value-initalization that for non-POD types is zero-initialization?

1 Answers

The syntax T object = {arg1, arg2, ...}; is copy list initialization. Since you established that T is not an aggregate type and that T has a default constructor (from the list) then list initialization will perform value initialization :

  • If T is an aggregate type, aggregate initialization is performed.
  • Otherwise, if the braced-init-list is empty and T is a class type with a default constructor, value-initialization is performed.
Related