C ++中delete和delete []之间的区别 [英] The difference between delete and delete [] in C++
本文介绍了C ++中delete和delete []之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个包含两个指针的类,一个是 char * color _
和一个在 vertexesset * vertex _
code> vertexesset 是我创建的类。在开始写的减法器
I've written a class that contains two pointers, one is char* color_
and one in vertexesset* vertex_
where vertexesset
is a class I created. In the destractor I've written at start
delete [] color_;
delete [] vertex_;
当它来的析构函数给它一个分段错误。
When It came to the destructor it gave me a segmentation fault.
然后我将析构函数改为:
Then I changed the destructor to:
delete [] color_;
delete vertex_;
现在它工作正常。
推荐答案
您 delete []
当你新
编辑数组类型, delete
时,示例:
You delete []
when you new
ed an array type, and delete
when you didn't. Examples:
typedef int int_array[10];
int* a = new int;
int* b = new int[10];
int* c = new int_array;
delete a;
delete[] b;
delete[] c; // this is a must! even if the new-line didn't use [].
这篇关于C ++中delete和delete []之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文