Here is a quick breakdown:
Celda is now a type. Think of it as replacing
Celda with
array<array<ColorCassila, 3>, 3>. Hence line 20 becomes
array<array<ColorCassila, 3>, 3> celda;
.
auto is a keyword to tell the compiler to work out the type of the variable itself, from the information given to it. Here are some examples:
1 2 3
|
auto x = 5; // x is an int
auto y = "Hello!"; // x is a char*
auto z = celda.begin(); // z is an array<array<ColorCasilla, 3>>::iterator
|
In your code, it simply retrieves the data type of the
celda object, like this:
1 2
|
// for (auto& linea : celda)
for (array<ColorCasilla, 3>& linea : celda)
|
Ranged based
for loops simply take a container of some kind, and loop through that container setting the variable to the contents of that container's iteration. For example, that loop is the same as:
|
for (size_t i = 0, auto& linea = celda[0]; i < celda.size(); ++i)
|
As a side note, that loop is wrong anyway, you probably wanted this:
1 2 3 4 5 6 7
|
void inisalizar() {
for (auto& linea : celda) {
for (auto& kase : linea) {
kase = ColorCasilla::VACIO;
}
}
}
|
If you don't understand, try looking up some of the things I mentioned, like range based for loops or the like.