mercredi 2 avril 2014

Using an initializer list for a 2D C style array in C++


Vote count:

0




I want to initialize a 2D array using the {} initializer but can't get it to work:



int** spiral = new int*[1001]{new int[1001] {0}};


The first row gets allocated and initialized to 0 but none of the other rows do.


This works but I'm pretty sure I can do this without a loop:



int** spiral = new int*[1001];
for (unsigned i = 0; i < 1001; i++)
spiral[i] = new int[1001] {0};


What am I missing here?



asked 57 secs ago






Aucun commentaire:

Enregistrer un commentaire