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
|