-1

So I have 2 dimensional array called char Screen[50][5]; When I declare it like this -> char Screen[50][5]; everything works. But when I put variables in square brackets instead of numbers I get the error saying Screen isn't declared.

I've tried this method of declaring char[][] Screen = new char[ScreenWidth][ScreenHeight]; too

int ScreenWidth = 50;
int ScreenHeight = 5;
char Screen[ScreenWidth][ScreenHeight];

[Error] 'Screen' was not declared in this scope

Boss
  • 21
  • 6

1 Answers1

0

That error is not related to you using variables for array sizes, however, this is not possible, C-Style array sizes have to be known at compiletime.

Your error is that you use Screen somewhere else, but this line errors, so Screen never gets defined.

Use the constexpr keyword for your variables, and it's possible

constexpr int ScreenWidth = 50;
constexpr int ScreenHeight = 5;
char Screen[ScreenWidth][ScreenHeight];

EDIT: You might be able to mark it const instead of constexpr, the compiler will most likely optimize that, but you can't rely on that.

JohnkaS
  • 622
  • 8
  • 18