What is the array form of 'delete'?
The array form of delete is:
delete [] data;
Edit: But as others have pointed out, you shouldn't be calling delete
for data defined like this:
int data[5];
You should only call it when you allocate the memory using new
like this:
int *data = new int[5];
You either want:
int *data = new int[5];
... // time passes, stuff happens to data[]
delete[] data;
or
int data[5];
... // time passes, stuff happens to data[]
// note no delete of data
The genera rule is: only apply delete
to memory that came from new
. If the array form of new
was used, then you must use the array form of delete
to match. If placement new
was used, then you either never call delete
at all, or use a matching placement delete
.
Since the variable int data[5]
is a statically allocated array, it cannot be passed to any form of the delete
operator.