urrrrrrrrrrrrrrrgh.
Last night, while doing programming exercises in C++, I discovered "Array Decay". Because arrays are just a fancy version of a pointer, when you pass them in as an argument to a function/method, they lose their array properties and are just treated like standard pointers. Normally this works fine; pointer notation allows you to use [] on it anyway. The issue is using Range-Based For loops for iteration over an array.
The Range-Based For loop looks like this:
for (tempType tempVariable : arrayName) {}
It's the equivalent of the foreach loop in C#. Each iteration of the loop, the tempVariable is equal to the current element of the array, and at the end of the iteration tempVariable is saved back to the element in arrayName. When your array and the range-based for loop are in the same scope, this works perfectly, however...
Because an array parameter is treated like a standard pointer, it loses certain necessary properties (such as array::begin) that the Range-Based For loop requires to work. Because there's no workaround for this and arrays don't have "length" property like in C#, you end up having to either manually keep track of the length of the array or hardcode a maximum number in and then break from the loop once it reaches some kind of terminator character.
Thoroughly frustrating.
EDIT: Should also mention; sizeof() correctly returns the length of your whole array in bytes when used in the same scope as the array. sizeof() only returns the length of the first element in an array in bytes when it is used on an array parameter. I was hoping to use simple maths (sizeof(arrayName) / sizeof(int)) to get the size of the array for this programming exercise, but that didn't work for the reasons I've said up above.