That compiles/runs fine and outputs that *pInt=5. But attempting to extend that type of initialization to arrays doesn't seem to work. With my older MinGW compiler I get this result when attempting to initialize an array of ints all to zero ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <cstdio>
int main()
{
int* pInt = newint[4](0);
for(int i=0; i<4; i++)
printf("pInt[%d] = %d\n",i,pInt[i]);
getchar();
return 0;
}
//-------------- Build: Release in Test ---------------
//Compiling: main.cpp
//C:\Code\CodeBlks\Test\main.cpp: In function 'int main()':
//C:\Code\CodeBlks\Test\main.cpp:5: error: ISO C++ forbids initialization in array new
//Process terminated with status 1 (0 minutes, 0 seconds)
//1 errors, 0 warnings
That's pretty plain English I'd say - "ISO C++ forbids initialization in array new".
However - and I find this bizarre - this compiles/runs perfectly, in spite of the fact that "ISO C++ forbids initialization in array new" ...
Thanks guys for the info. I'm more a C coder than a C++ one, and just wasn't sure that syntax was right. I just wasn't familiar with it. I had been using memset() to zero out the arrays, and a friend showed me the []() thing, and I was somewhat taken aback with it having never seen it. Could see it worked, but couldn't figure out if it was ledgit.