Declaring the array size with a non-constant variable

Solution 1:

This is a GCC extension to the standard:

You can use the -pedantic option to cause GCC to issue a warning, or -std=c++98 to make in an error, when you use one of these extensions (in case portability is a concern).

Solution 2:

You are using a feature from C99 which is called VLA(variable length arrays). It would be better if you compile your program like this:

g++ -Wall -std=c++98 myprog.cpp