[英]How can i delete a pointer to array in C++
I am wondering how can i use the delete operator if I want to delete an array initialized like this:我想知道如果我想删除这样初始化的数组,我该如何使用 delete 运算符:
int (*my_ptr)[10] = new int[3][10];
This seems invalid:这似乎无效:
delete[][]
new int[3][10]
is simply creation of a dynamic array whose elements are themselves arrays. new int[3][10]
只是创建一个动态数组,其元素本身就是数组。 This is deleted in the same way as all dynamic arrays: delete[]
.它的删除方式与所有动态数组相同: delete[]
。
my_ptr
is an array of 3 elements. my_ptr
是一个包含 3 个元素的数组。 Each element is an int[10]
type.每个元素都是int[10]
类型。
You call delete[] my_ptr;
你打电话给delete[] my_ptr;
to delete those 3 elements.删除这 3 个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.