2

We know std::array<double, N> Can be initialized to all-zero by

std::array<double, N> my_array {}

My question is if I have

std::array<std::array<double, N>, M> my_array {}

Doess the above guarantee the nested array is also all initialized to 0.0? If so, how does the {} work in this scenario? If not, what can I achieve that?

2
  • 4
    Yes, the above guarantees that the elements of the array of arrays are all initialized to zero. The {} works in this scenario the usual way for aggregate initialization (which is part of list-initialization) syntax. Commented Jan 13 at 13:30
  • 4
    Aggregate initialization initializes members with missing initializer expressions to default. If the members are aggregates, then that's another round of aggregate initialization. Default initialization for fundamental types is 0.std::array is demanded by standard to be aggregate. So you get 2 levels of aggregate initialization due to default construction request and zeroing on 3rd level for default construction request on fundamental types. Commented Jan 13 at 14:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.