M
mooingpsychoduck
Someone online (http://stackoverflow.com/q/17091991/845092) was trying to initialize a variable like so:
int (**a)[10] = new [10][20][30];
And (regardless of what he _actually_ wanted), I quickly discovered that without a typedef I could initialize "a" to (a dynamic pointer to a (pointer to (an array of ten integers))), but without a typedef I could NOT initialize "a" to (a dynamic array of 30 (pointers to (an array of ten integers))).Succinctly:
//this line compiles fine
int (**a)[10] = new (int (*)[10]);
//error: array bound forbidden after parenthesized type-id
int (**a)[10] = new (int (*)[10])[30];
Is there a trick to this I haven't thought of, or is it actually impossibleto do this without a typedef? One can easily use typedefs, or type deduction, or any number of other tricks as a workaround, but I was surprised that I could not do this as a "basic" expression.
(Please don't speculate new expressions that you think might work without testing them in a compiler first. My friends and I have already tested many permutations. Random guesses are not going to be helpful here.)
int (**a)[10] = new [10][20][30];
And (regardless of what he _actually_ wanted), I quickly discovered that without a typedef I could initialize "a" to (a dynamic pointer to a (pointer to (an array of ten integers))), but without a typedef I could NOT initialize "a" to (a dynamic array of 30 (pointers to (an array of ten integers))).Succinctly:
//this line compiles fine
int (**a)[10] = new (int (*)[10]);
//error: array bound forbidden after parenthesized type-id
int (**a)[10] = new (int (*)[10])[30];
Is there a trick to this I haven't thought of, or is it actually impossibleto do this without a typedef? One can easily use typedefs, or type deduction, or any number of other tricks as a workaround, but I was surprised that I could not do this as a "basic" expression.
(Please don't speculate new expressions that you think might work without testing them in a compiler first. My friends and I have already tested many permutations. Random guesses are not going to be helpful here.)