Here is what I’ve copied from MSDN about new operator:
The
newoperator cannot be used to allocate a function, but it can be
used to allocate pointers to functions. The following example
allocates and then frees an array of seven pointers to functions that
return integers.int (**p) () = new (int (*[7]) ()); delete *p;
Well there is nothing strange with first line, it allocates an array of pointers to functions, but I just don’t understand how the second deletes that array? I think it should be:
delete[] *p;
Can anyone explain this?
Frankly speaking the right answer was written in the avakar’s comment.
The right code is
delete *p;is incorrect for two reasons:delete[]for all dynamically allocated arrays. Usingdeletewill cause an undefined behaviour.