Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+中初始化二维数组+;_C++_Multidimensional Array - Fatal编程技术网

C++ 在C+中初始化二维数组+;

C++ 在C+中初始化二维数组+;,c++,multidimensional-array,C++,Multidimensional Array,我试图用下面的代码初始化2d arary- int main(void) { int arr[][5] = { [0][1] : 1, [0][0] : 2, [0][2] : 3, }; cout<<a[0][0]<<" "<<a[0][1]<<endl; return 0; } int main(无效) { int arr[][5]={ [0][1] : 1, [0][0]

我试图用下面的代码初始化2d arary-

int main(void)
{
    int arr[][5] = {
        [0][1] : 1, [0][0] : 2, [0][2] : 3,
    };
    cout<<a[0][0]<<" "<<a[0][1]<<endl;

    return 0;
}
int main(无效)
{
int arr[][5]={
[0][1] : 1, [0][0] : 2, [0][2] : 3,
};

cout我在
中找到了以下代码快照 说明上述初始化对C++无效。

struct A { int x, y; };
struct B { struct A a; };
struct A a = {.y = 1, .x = 2}; // valid C, invalid C++ (out of order)
**int arr[3] = {[1] = 5};        // valid C, invalid C++ (array)**
struct B b = {.a.x = 0};       // valid C, invalid C++ (nested)
struct A a = {.x = 1, 2};      // valid C, invalid C++ (mixed)

<不可能在C++中使用[]的指定初始化,因为它在C. < /P>中,因为C允许何时<代码> [0 ] [ 1 ]:1
?@TonyTannous自1999年以来;)@Quentin这就是我喜欢的原因。你总是能学到一些新东西。虽然我从未见过一个例子…我应该搜索什么来找到一些?@TonyTannous这些被称为指定的初始值设定项,但是
是一个编译器扩展——标准的使用
=
@Quentin我知道它们是受支持的在C99中,D被引入C++ 20中的C++中,奇怪的是<> >:<代码> >,现在我理解的是编译器扩展。
struct A { int x, y; };
struct B { struct A a; };
struct A a = {.y = 1, .x = 2}; // valid C, invalid C++ (out of order)
**int arr[3] = {[1] = 5};        // valid C, invalid C++ (array)**
struct B b = {.a.x = 0};       // valid C, invalid C++ (nested)
struct A a = {.x = 1, 2};      // valid C, invalid C++ (mixed)