【发布时间】:2014-07-24 17:46:39
【问题描述】:
我有以下数组:
int const A[4] = { 0, 1, 2, 3 };
我要初始化一个重复数组,如下:
int a[4] = A;
如果我在 cygwin 上运行 g++ 4.8.2 如下:
g++ --std=c++11 myfile.cpp
我收到以下错误:
myfile.cpp:16:16: error: array must be initialized with a brace-enclosed initializer
int a[4] = A;
^
但是,显然“int a[4] = { A };”也不起作用。有没有办法使用简单的赋值语句从A 初始化我的数组a 而无需求助于:
int a[4] = { A[0], A[1], A[2], A[3] };
?
【问题讨论】:
标签: c++ c++11 compiler-errors constants constant-expression