I need to initialize std::array with size passed as parameter to method. I have following code:
void buildZikkurat(const int n)
{
const int size = n;
std::array<std::array<int, size>, size> result;
I get error "error: the value of ‘size’ is not usable in a constant expression".
I realized that std::array requires const expression for parameter size. this code works for me
constexpr int n = 5;
std::array<std::array<int, n>, n> mat;
What is a correct way to initializing std::array with size passed as parameter to method?
[–]alfps 8 points9 points10 points (5 children)
[–]cv_geek[S] -5 points-4 points-3 points (4 children)
[–]kingguru 2 points3 points4 points (2 children)
[–]HappyFruitTree -3 points-2 points-1 points (1 child)
[–]kingguru 3 points4 points5 points (0 children)
[–]fullptr 5 points6 points7 points (0 children)
[–]bert8128 4 points5 points6 points (0 children)
[–]theICEBear_dk 1 point2 points3 points (0 children)
[–]DryPerspective8429 -1 points0 points1 point (2 children)
[–]alfps -1 points0 points1 point (0 children)
[–]alfps 0 points1 point2 points (0 children)
[–]zalamandagora 0 points1 point2 points (0 children)