Other answers already provide a solution, g ++ allows arrays of variable arrays (VLAs) as an extension in C ++ (technically, VLA is a C function from C90). To make sure you are using standard compatible C ++, go -pedantic to get the warning, and -pedantic -Werror to make the warning difficult.
I recommend the following when compiling in debug mode:
g ++ -std = C ++ 11 -O0 -g3 -pedantic -pedantic-errors -Wall -Wextra -Werror -Wconversion
O0 is the optimization flag and -g3 used for debugging . They need to be changed if you want to use optimization and do not need debugging. However, sometimes you may need to remove -Werror -Wconversion , since you will not be able to change the code for certain reasons, for example, when using third-party libraries. For a description of what each of them does, send here .
source share