If you dynamically allocate an array type, you get a pointer to its first element.
§5.3.4 [expr.new] Entities created by a new-expression have dynamic storage duration. If the entity is a non-
array object, [...]. If it is an array, the new-expression returns a pointer to the initial element of the array.
So since you're allocating an array type object, you get an int*
out of it:
int *p = new Array;
This is no different to not using the typedef:
int *p = new int[2];
This also doesn't match your T *p = new T;
rule. That is, you definitely can't do this:
int (*p)[2] = new int[2];
I realise this confusion may have been caused by thinking of new ...[]
as a special type of expression different to new ...
, where new Array
fits into the latter case. We often suggest it might be by saying things like "new[]
should always match with delete[]
". Well that rule is a little misleading. What is really meant here is that new
with an array type should always be matched with delete[]
.