Why “delete [][]… multiDimensionalArray;” operator in C++ does not exist

后端 未结 9 990
清酒与你
清酒与你 2021-02-05 06:09

I was always wondering if there is operator for deleting multi dimensional arrays in the standard C++ language.

If we have created a pointer to a single dimensional arra

9条回答
  •  一向
    一向 (楼主)
    2021-02-05 06:49

    not sure of the exact reason from a language design perspective, I' guessing it has something to do with that fact that when allocating memory you are creating an array of arrays and each one needs to be deleted.

    int ** mArr = new int*[10];
    for(int i=0;i<10;i++)
    {
       mArr[i]=new int[10];
    }
    

    my c++ is rusty, I'm not sure if thats syntactically correct, but I think its close.

提交回复
热议问题