C/C++ Arena

Step 1 of 5

Making a class iterable

Range-for is rewritten by the compiler into iterator calls:

for (auto& x : c) { ... }
// becomes roughly:
for (auto it = c.begin(), end = c.end(); it != end; ++it) { auto& x = *it; ... }

So any type with begin() and end() members works with range-for, and with every standard algorithm. If your class stores its data contiguously, plain pointers are perfectly good iterators.

Your turn: give Scoreboard begin() and end() (both a non-const and a const version) that return pointers into its fixed array, covering only the count_ scores that were added.

Next: Writing an iterator class