How do you initialize (through initializer lists) a multidimensional std::array in C++11?

后端 未结 2 1255
我寻月下人不归
我寻月下人不归 2020-12-16 14:57

I am trying to initialize a 2D std::array trough initializer lists however the compiler tells me that there are too many initializers.

e.g.:

std::ar         


        
2条回答
  •  别那么骄傲
    2020-12-16 15:35

    Try to add one more pair {} to ensure we're initializing the internal C array.

    std::array, 2> shape = {{ {1, 1},
                                                 {1, 1} }};
    

    Or just drop all the brackets.

    std::array, 2> shape = { 1, 1,
                                                1, 1 };
    

提交回复
热议问题