Why can’t I use the new operator like this:
char* p;
p = new char('a')[3];
delete[] p;
Compiler says:
error C2143: syntax error : missing ';' before '['
error C3409: empty attribute block is not allowed
error C2143: syntax error : missing ']' before 'constant'
In C++11, you can initialize a dynamically allocated aggregate through the new uniform initialization:
In C++98, you cannot specify an initializer list for dynamically-allocated aggregates.
All you can do is to first allocate the array, then fill it with a value: