What you wrote is valid in c99 , but not valid C ++ .
Of course, I'm talking about your use of VLA , not the full snippet.
When compiling using g++ -pedantic -ansi -Wall we get the warning below:
foo.cpp: In member function 'void Test::foo()': foo.cpp:18:23: warning: ISO C++ forbids variable length array 'array' [-Wvla]
As mentioned above, the pattern you use is often referred to as using a variable-length array, which is standard in C99 and is "allowed" in C ++ through the g ++ extension.
I would recommend you use an STL container instead of hacks, as this is for one single reason; what you do is not legal and therefore portable cross-compilers are not guaranteed.
source share