The following code works but I have been told that it doesn't compile with gcc 3.4.2 with Visual C++ 2010 and may be illegal:
int ar1[]{0,1,2,3,4,5,6,7,8,9},
*ptr1 = ar1,
ar2[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18},
*ptr2 = ar2;
Apparently you need to make some modifications for it to work (something like that):
int ar1[]{0,1,2,3,4,5,6,7,8,9};
int *ptr1 = ar1;
int ar2[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
int *ptr2 = ar2;
Is that right? Can't arrays and pointers be declared together?
(The code compiles fine on QT + gcc 4.8)
The declaration in question uses C++11 initialization syntax. It is not syntactically correct from the point of view of pre-C++11 compiler. But if you add a =
before each {
it will become ordinary and perfectly legal C++98 declaration (and C declaration as well).
There's no problem in using several declarators in one declaration, even if you mix pointer and array declarators. You can add function declarators into that mix, if you wish. The only restriction is that you can't embed function definitions in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With