c++ - Creating an array with a variable -


i have 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

error c2057: expected constant expression

ok, how can create matrix shown in code without vectors or dynamic allocated array?

as error says, need constant expressions define array/matrix sizes; in example, make integers const , compile.

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

if don't want dynamically allocated arrays or vectors, you'll have know exact array size beforehand.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -