0
const int cntVrt = obtTotVrt();
const int totSal = obtTotAdy(vrt);
const int totEnt = obtTotAdyEntrantes(vrt);
const int cntVecinos = totSal + totEnt;

int vecinos[cntVecinos];

Last line throws the error, Im using a const but I read it depends on compiler? How can I fix that using simple arrays?

PS. I was using Netbeans but swapped to VS to track down a bug where an object pointed to by an "int * array" changes values and now Im getting this error.

andrescr94
  • 57
  • 1
  • 8
  • You are declaring a [variable-length array](http://en.cppreference.com/w/c/language/array#Variable-length_arrays). This is a feature of the C language that's not valid in C++, but some C++ compilers support it as an extension. Visual Studio does not; apparently, whatever compiler comes with NetBeans does. – Igor Tandetnik Oct 16 '17 at 01:06
  • ["Variable-length automatic arrays are allowed in ISO C99, and as an extension GCC accepts them in C90 mode and in C++"](https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html). [Clang also supports it as an extension](https://stackoverflow.com/q/17645496/995714) – phuclv Oct 16 '17 at 01:09
  • Yes, so I should be using the dynamic arrays with new and delete, I understand, thanks. – andrescr94 Oct 16 '17 at 01:13
  • [Enabling VLAs(variable length arrays) in MS Visual C++?](https://stackoverflow.com/q/5246900/995714) – phuclv Oct 16 '17 at 01:25
  • @andrescr94 No, you should be using std::vector. – DeiDei Oct 16 '17 at 02:08
  • Sure, but I need simple arrays... Went with smart pointers finally. – andrescr94 Oct 16 '17 at 02:20

0 Answers0