为什么"删除[] [] ... multiDimensionalArray;"运营商在C ++中不存在 [英] Why "delete [][]... multiDimensionalArray;" operator in C++ does not exist

查看:86
本文介绍了为什么"删除[] [] ... multiDimensionalArray;"运营商在C ++中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是想知道是否有在标准C ++语言中删除多维数组运算符。

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 array

int *array = new int[size];

删除如下:

delete [] array;

这是伟大的。但是,如果我们有两个二维数组,我们不能做。

That's great. But if we have two dimension array, we can not do

delete [][] twoDimenstionalArray;

相反,我们应该循环并删除项,如这个例子。

任何人都可以解释,为什么?

Can anybody explain why?

推荐答案

从技术上讲,有在C不是二维数组++。什么您使用作为二维阵列是一维阵列,每个元件是一维阵列。因为它不存在技术上,C ++无法删除它。

Technically, there aren't two dimensional arrays in C++. What you're using as a two dimensional array is a one dimensional array with each element being a one dimensional array. Since it doesn't technically exist, C++ can't delete it.

这篇关于为什么"删除[] [] ... multiDimensionalArray;"运营商在C ++中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆