A
Alf P. Steinbach
* Ron Natalie:
Right. Sorry about the typos ("B" instead of "b", and unstated
assumption of PODness). The point remains: if B is a POD it will not be
initialized (the standard states in §8/9 that it will have an
"indeterminate initial value", as opposed to being default-initialized).
Not relevant to that point, but I think relevant to those who might read
this: regardless of B's PODness, without a user-defined constructor POD
members won't be initialized here (§12.1/7).
To ensure initialization you need a user-defined constructor, even
though as I exemplified earlier that's not an absolute guarantee, only
an effective guarantee for sensible code.
Nope. The object b above is not value-initialized. It's either not
initialized at all, or if non-POD, the default constructor is called.
Value initialization applies to an expression such as
B();
see §8.5/7, and the intent is that the effect of this expression should
not depend on whether there is a non-POD member or not: that this
expression should always give some initialization of all members,
zeroing all POD stuff.
There is an implicitly defined consturctor (admittedly rarely actually
causing executable code), but it depends on what the definition of B
is.
Right. Sorry about the typos ("B" instead of "b", and unstated
assumption of PODness). The point remains: if B is a POD it will not be
initialized (the standard states in §8/9 that it will have an
"indeterminate initial value", as opposed to being default-initialized).
Not relevant to that point, but I think relevant to those who might read
this: regardless of B's PODness, without a user-defined constructor POD
members won't be initialized here (§12.1/7).
To ensure initialization you need a user-defined constructor, even
though as I exemplified earlier that's not an absolute guarantee, only
an effective guarantee for sensible code.
This is actually the who reason the term "value initialized" was
invented.
Nope. The object b above is not value-initialized. It's either not
initialized at all, or if non-POD, the default constructor is called.
Value initialization applies to an expression such as
B();
see §8.5/7, and the intent is that the effect of this expression should
not depend on whether there is a non-POD member or not: that this
expression should always give some initialization of all members,
zeroing all POD stuff.