Confusion with the auto type and other types
1 2 3 4 5 6 7 8 9 10
|
constexpr size_t rowCnt = 3, colCnt = 4;
int ia[rowCnt][colCnt] = {
{ 3, 6, 9, 12 },
{ 2, 4, 6, 8 },
{ 1, 2, 3, 4 }
};
for (auto &row : ia) // Right here
for (auto col : row) // and here
cout << col << endl;
|
What would I use instead of auto?
1 2 3
|
for (int(&row)[4] : ia) // row is a reference to an array of 4 int.
for (int col : row) // col is an int.
cout << col << endl;
|
Would be equivalent.
Thanks for the response. I tried a similar approach but I had forgotten the parenthesis.
Topic archived. No new replies allowed.