I was asking myself something this morning, and I can't find the words to properly "google" for it:
Lets say I have:
struct Foo
{
int bar;
};
struct Foo2
{
int bar;
Foo2() {}
};
struct Foo3
{
int bar;
Foo3() : bar(0) {}
};
Now, if I default-initialize Foo
, Foo2
and Foo3
:
Foo foo;
Foo2 foo2;
Foo3 foo3;
In which case(s) is the bar
member properly initialized, meaning that its value isn't indeterminate?
Note: Foo3
obviously initialized. It is only shown here to display the difference to Foo2
, so the question is mainly about the first two.
Only foo3 will be in all contexts. foo2 and foo will be if they are of static duration. Note that objects of type Foo may be zero initialized in other contexts:
while Foo2 will not:
that area is tricky, the wording as changed between C++98 and C++03 and, IIRC, again with C++0X, so I'd not depend on it.
With
bar will always be initialized as well.