1

I have the following code:

#include <iostream>

using namespace std;

int main()
{
   unsigned int endx = 5;
   unsigned int endy = 5;
   unsigned int endz = 5;

   int Matrix[endx+1][endy+1][endz+1] = {};

   return 0;
}

I get

error C2057: expected constant expression

Ok, how can I create the Matrix like shown in the code without vectors or dynamic allocated array?

Peter Parker
  • 93
  • 1
  • 8

2 Answers2

2

Arrays require constants when creating them. In this code, just making your end* variables const unsigned int should do it.

Jay Miller
  • 2,184
  • 12
  • 11
2

As the error says, you need constant expressions to define array/matrix sizes; in that example, make integers const and it will compile.

const unsigned int endx = 5;
const unsigned int endy = 5;
const unsigned int endz = 5;

If you don't want dynamically allocated arrays or vectors, then you'll have to know the exact array size beforehand.

outlyer
  • 3,933
  • 2
  • 14
  • 18