struct MyClass
{
std::array<int, 10> stdArr;
MyClass() : stdArr()
{}
};
MyClass c;
Questions:
- Is
c.stdArrzero-initialized? - If yes - why?
My own contradictory answers:
It is zero-initialized:
std::arraywants to behave like a c-array. If in my example abovestdArrwas a c-array, it would be zero-initialized bystdArr()in the initialization list. I expect that writingmember()inside of an initialization list initializes the object.It's not zero-initialized:
std::arraynormally has a single member which is in my caseint[10] _Elems;- normally fundamental types and arrays of fundamental types like
int[N]are not default-initialized. std::arrayis an aggregate type which implies that it is default-constructed.- because there is no custom constructor which initializes
_Elems, I think it is not zero-initialized.
What's the correct behaviour of std::array according to the C++11 Standard?