0

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.

4
  • 3
    How is pos defined? Commented Mar 26, 2013 at 13:39
  • 1
    You must include the declaration of pos in order to understand this line. It could be a container of function pointers, e.g. Commented Mar 26, 2013 at 13:41
  • The important thing here is that it's not some strange syntax you've never seen before. It's just accessing an array and then calling a function. Commented Mar 26, 2013 at 13:47
  • 1
    Does this code compile? Is it an example from a book? The (1) could be a cross-reference to some description, and not meant to be part of the code at all. Commented Mar 26, 2013 at 13:49

1 Answer 1

5
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).

Sign up to request clarification or add additional context in comments.

1 Comment

It could also be a pointer to a function pointer... just too many possibilities...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.