dimanche 24 janvier 2016

Why this for loop isn't valid?

int ia[3][4];
for (auto row : ia)
        for (auto col : row)

The first for iterates through ia, whose elements are arrays of size 4. Because row is not a reference, when the compiler initializes row it will convert each array element (like any other object of array type) to a pointer to that array’s first element. As a result, in this loop the type of row is int*.

I am not really sure that I understand how this auto works, but If I can assume it automatically gives a type to a row based on ia array members type, but I don't understand why this kind of for, where row is not a reference is not valid. Why this gonna happen 'pointer to that array’s first element', because of what? Please help me to understand this, thanks.

Aucun commentaire:

Enregistrer un commentaire