Hi, I don´t know why when I try to build this code with Visual Studio it returns an error, but if I do it with Code Blocks it runs perfect. Im using Visual Studio 15
expression must have a constant value
Error C2131 expression did not evaluate to a constant
Error C3863 array type 'unsigned int [numpos][9]' is not assignable
I don´t know why it runs in code blocks but don´t in Visual...
you cannot, in C++, allocate an array from a variable because arrays have a fixed size created at run time.
either make numpos a constant, or make solucion a pointer. You can allocate a pointer of variable size and resize it if you must.
Welcome to c++... where illegal code can work fine in some compilers and IDES and not in others. Actually, legal code can have some problems as well, portability is a bit of a problem with the language at times.
Variable-length array (VLA) is a feature that exists in C but not in C++.
GCC (which I assume is the compiler that you were using with Code::Blocks) allows VLA as an extension by default, but if you explicitly request standard conformance by using the compiler flag -pedantic-errors you will get an error.
1 2
unsigned numpos = 3;
unsigned solucion[numpos][9]; // error: ISO C++ forbids variable length array ‘solucion’