struct MyClass
{
std::array<int, 10> stdArr;
MyClass() : stdArr()
{}
};
MyClass c;
Questions:
c.stdArr
zero-initialized?My own contradictory answers:
It is zero-initialized:
std::array
wants to behave like a c-array.
If in my example above stdArr
was a c-array, it would be zero-initialized by stdArr()
in the initialization list. I expect that writing member()
inside of an initialization list initializes the object.
It's not zero-initialized:
std::array
normally has a single member which is in my case int[10] _Elems;
int[N]
are not default-initialized.std::array
is an aggregate type which implies that it is default-constructed._Elems
, I think it is not zero-initialized.What's the correct behaviour of std::array
according to the C++11 Standard?
Is
c.stdArr
zero-initialized?
Yes
If yes - why?
This performs a value initialization of stdArr
:
MyClass() : stdArr() {}
In this context, the effect of the value initialization is a zero initialization of the object.
Edit: there is plenty of relevant information in What are Aggregates and PODs...?