我正在尝试定义一个堆栈 c 样式数组,其大小取自 const 数组并且在编译时已知。
const int size[2]={100, 100};
int ar[size[0]]; //error: expression must have a constant value
它失败了。如何修复?
最佳答案
“其大小取自 const 数组且在编译时中已知的数组”
使用 C++11,您可以:
constexpr int size[2]={100, 100};//size[0] 是编译时常量
使用-std=c++11
或-std=c++0x
编译
关于C++ 声明其大小值来自 const 数组的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18984971/