[16.11] How do I allocate / unallocate an array of things?
Use p = new T[n] and delete[] p:
Fred* p = new Fred[100];
...
delete[] p;
Any time you allocate an array of objects via
new (usually with the
[n] in the
new expression), you
must use
[] in the
delete statement. This syntax is necessary because there
is no syntactic difference between a pointer to a thing and a pointer to an
array of things (something we inherited from C).