Initialize Initialization of Inline Elements

Bjarne Stroustrup C ++ Programming Language, 4th Edition, 17.6.3.1 states that

Initializing the default inline element by default leaves the member uninitialized.

referring to the default compiler generated constructor.

However, in 17.6.2 we have the following code

struct S {
  string a;
  int b;
};

S f(S arg)
{
  S s0 {};     // default construction: {"",0}
..
}

where b is initialized to 0 by default.

So what am I missing here?

+4
source share
1 answer

You do aggregate initialization , "not initialization by default. And as part of aggregate initialization, unspecified members go through initialization of values ​​(for example, zero for integers).

+5
source

All Articles