http://www.ddj.com/cpp/184403285
What happens if you mix them up? That is, what happens if you attempt to deallocate an array using non-array delete, or vice versa? The draft C++ standard says the behavior is undefined. That is, something bad may happen, maybe now or maybe later. More precisely, a program that uses the wrong form of delete-expression has committed an error which neither the compiler nor the runtime system is obligated to diagnose. The program might terminate abruptly, or limp along producing erroneous results. It might even get away seemingly unscathed.
if you do:
int * a = new int[10];
....................
delete[] a; a = NULL;
//delete a; a = NULL; <==== so wrong
always use delete[] for a dynamic array. Even experienced programmers often make this type errors. However, you can find this problem if you use valgrind to check your code.
[ 此贴被steinlee在2008-07-31 00:35重新编辑 ]