Multidimensional std::array

C++Stl

C++ Problem Overview


In C++, how do I create a multidimensional std::array? I've tried this:

std::array<std::array<int, 3>, 3> arr = {{5, 8, 2}, {8, 3, 1}, {5, 3, 9}};

But it doesn't work. What am I doing wrong and how do I fix this?

C++ Solutions


Solution 1 - C++

You need extra brackets, until c++14 proposal kicks in.

std::array<std::array<int, 3>, 3> arr = {{{5, 8, 2}, {8, 3, 1}, {5, 3, 9}}};

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLazySloth13View Question on Stackoverflow
Solution 1 - C++billzView Answer on Stackoverflow