由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ delete[]
相关主题
请教一个C++有关的编译问题问个object suicide问题
C++ linking 弱问 (one file)c++里 weak_ptr用起来是不是耗时间?
弱问一下What is wrong in this array declaration.
[合集] C++ question -- how to save objectsC++ vector
问问开发ios的,有用C++来组织代码的么?[转载] Tcl/C++ question
C, C++, Java, C#, Objective-C,C++ class cross reference problem
问个C++中重复删除指针的问题some C++ interview questions
one question about overloading operator deleteC++ question
相关话题的讨论汇总
话题: delete话题: circle话题: sarray话题: new话题: c++
进入Programming版参与讨论
1 (共1页)
i**p
发帖数: 902
1
delete[] does not work here.
Do I have to delete the 3 objects one by one?
Circle *sarray[] = {new Circle, new Circle, new Circle};
delete[] sarray; // core dump
S**I
发帖数: 15689
2
这还用说,当然了。

【在 i**p 的大作中提到】
: delete[] does not work here.
: Do I have to delete the 3 objects one by one?
: Circle *sarray[] = {new Circle, new Circle, new Circle};
: delete[] sarray; // core dump

X****r
发帖数: 3557
3
just remember a simple rule: "new" matches "delete" and "new TYPE[]" matches
"delete[]"

【在 i**p 的大作中提到】
: delete[] does not work here.
: Do I have to delete the 3 objects one by one?
: Circle *sarray[] = {new Circle, new Circle, new Circle};
: delete[] sarray; // core dump

i**p
发帖数: 902
4
It is not good to delete these objects one by one, though I can use a loop
to do it. I am trying to find a statement like delete[] to remove all of
them in one line of code.

matches

【在 X****r 的大作中提到】
: just remember a simple rule: "new" matches "delete" and "new TYPE[]" matches
: "delete[]"

b*******s
发帖数: 5216
5
for (auto & ptr: arr) { delete ptr; }

【在 i**p 的大作中提到】
: It is not good to delete these objects one by one, though I can use a loop
: to do it. I am trying to find a statement like delete[] to remove all of
: them in one line of code.
:
: matches

t*****n
发帖数: 4908
6
有两组new,一组delete,当然不行。没必要追求代码写的多好看。能work就行。

【在 i**p 的大作中提到】
: It is not good to delete these objects one by one, though I can use a loop
: to do it. I am trying to find a statement like delete[] to remove all of
: them in one line of code.
:
: matches

1 (共1页)
进入Programming版参与讨论
相关主题
C++ question问问开发ios的,有用C++来组织代码的么?
关于effective c++的几个问题C, C++, Java, C#, Objective-C,
C++ questions问个C++中重复删除指针的问题
C++ interdependence questionone question about overloading operator delete
请教一个C++有关的编译问题问个object suicide问题
C++ linking 弱问 (one file)c++里 weak_ptr用起来是不是耗时间?
弱问一下What is wrong in this array declaration.
[合集] C++ question -- how to save objectsC++ vector
相关话题的讨论汇总
话题: delete话题: circle话题: sarray话题: new话题: c++