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

后端 未结 9 1006
清酒与你
清酒与你 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:46

    You can use a wrapper class to do all those things for you. Working with "primitive" data types usually is not a good solution (the arrays should be encapsulated in a class). For example std::vector is a very good example that does this.

    Delete should be called exactly how many times new is called. Because you cannot call "a = new X[a][b]" you cannot also call "delete [][]a".

    Technically it's a good design decision preventing the appearance of weird initialization of an entire n-dimensional matrix.

提交回复
热议问题