琐碎的C++代码......为什么要编译?

Kia*_*ian 2 c++ arrays

这样的 C++教程说,所有数组的大小必须在程序运行之前确定.例如,这是不允许的:

cout << "How many variables do you want? ";
int nVars;
cin >> nVars;

int anArray[nVars]; // wrong!  The size of the array must be a constant
Run Code Online (Sandbox Code Playgroud)

但这个简单的程序确实可以编译和执行.应该吗?

das*_*ght 6

这是C++编译器实现的通用扩展,例如GNU的g ++.使用-std=c++0xflag 编译将此类声明视为错误.