In Delete [], [] indicates C ++, pointing to an array. If the length of the array is specified in [], the C ++ compilation system will ignore it, and treat it. However, if you forget to write [],ProgramA running error occurs.
Delete calls the Destructor only once, while Delete [] calls the destructor of each member. In more efficient C ++, there is a more detailed explanation: "When the delete operator is used for an array, it calls the Destructor for each array element, and then calls operatordelete to release the memory ." Supports Delete and new, and supports Delete [] and new []
Memtest * mtest1 = newmemtest [10];
Memtest * mtest2 = newmemtest;
Int * pint1 = newint [10];
Int * pint2 = newint;
Delete [] pint1; //-1-
Delete [] pint2; //-2-
Delete [] mtest1; //-3-
Delete [] mtest2; //-4-
An error is reported at-4.
This indicates that the delete and delete [] functions are the same for built-in simple data types. For custom complex data types, delete and delete [] cannot be mutually used. Delete [] delete an array and delete a pointer In short, use Delete to delete the memory allocated by New , delete the memory allocated with New [] with Delete [] . Delete [] calls the destructor of the array element. Internal data types do not have destructor, so there is no problem. If you do not use parentheses when using Delete, delete will think that it points to a single object. Otherwise, it will think that it points to an array.