I've just come across this in code and I don't understand what it's doing, or how it's doing what it's doing
pos[iter](1) += 12.0f / 900.0f;
does the (1) initialise the array value at position iter to 1, then add (12.0f / 900.0f) to it? I can't believe it is as it's being used in a loop to set the position of debug text, each loop sets the next line below to a high y value (lower point on screen). iter can be 0 or 1 depending on what list the debug text is in.
I would understand if it were a static operation.
1 Answer 1
pos[iter](1) += 12.0f / 900.0f;
pos can be an array, map, or an object of a class with an overloaded operator[]. pos[iter] returns an object (could be a function pointer, lambda or a class with an overloaded operator()) and calls it with a parameter of 1. The function call most likely returns a reference to the returned object as you can mutate its value using +=.
So to make it clear, (1) is not accessing the 2nd element of anything. It's simply a call to a function or method with that argument. The method returns some object that has a suitable overload of operator += (could be a scalar or an actual class).
posdefined?posin order to understand this line. It could be a container of function pointers, e.g.(1)could be a cross-reference to some description, and not meant to be part of the code at all.