Is it possible to make the same thing without type alias?
void f()
{
typedef char Str[16];
int n=256;
Str** p = new Str*[n];
delete[] p;
}
I tried the following but didn't work:
// char(**p)[16] = new char(*[n])[16]; // error
// char(**p)[16] = new (char(*[n])[16]); // error
It seems that you want to create a dynamic array where the element type is char (*)[16]
. No, it can't be done without a type alias. In order to use a dynamic extent, you need to use the following form of a new-expression (C++17 [expr.new]/1):
::
(opt)new
new-placement(opt) new-type-id new-initializer(opt)
But if you look at the definitions of new-type-id, new-declarator, and noptr-new-declarator, you see that parentheses are not allowed for altering operator precedence. Thus, we can't explicitly write down the desired type in this context.
Best solution: use std::vector
. If you can't do that (maybe you are targeting some very limited freestanding implementation) then use the typedef.