struct MyClass
{
std::array<int, 10> stdArr;
MyClass() : stdArr()
{}
};
MyClass c;
Questions:
- Is
c.stdArr
zero-initialized? - If yes - why?
My own contradictory answers:
It is zero-initialized:
std::array
wants to behave like a c-array. If in my example abovestdArr
was 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::array
normally 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::array
is 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?