【发布时间】:2013-09-24 14:52:09
【问题描述】:
我正在尝试定义一个堆栈 c 样式数组,其大小取自 const 数组并且在编译时是已知的。
const int size[2]={100, 100};
int ar[size[0]]; //error: expression must have a constant value
失败了。怎么解决?
【问题讨论】:
-
它适用于 g++4.4。它也适用于ideone
-
如果您在编译时知道大小,您可以始终将其作为数组大小粘贴
-
@cpp:那是因为 GCC 支持 C 风格的可变长度数组作为非标准扩展。
标签: c++ arrays constants constexpr compile-time-constant