bug*_*lux 2 c c++ static gcc initialization
以下代码适用于GCC的C编译器,但不适用于C++编译器.是否有"快捷方式"在C++中实现相同的结果?
int array[10] = {
[1] = 1,
[2] = 2,
[9] = 9
};
Run Code Online (Sandbox Code Playgroud)
编辑:嗯,我发现了这一点,澄清了一切. http://eli.thegreenplace.net/2011/02/15/array-initialization-with-enum-indices-in-c-but-not-c/
小智 5
这种初始化形式仅在C99标准中定义.它并不能适用于C++.所以,你必须逐个分配你的元素:
int array[10] = { 0 };
array[1] = 1;
array[2] = 2;
array[9] = 9;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6107 次 |
最近记录: |