0

A simple function

auto f = [] (const array <GLfloat, 4> a, array <GLfloat, 4> b) {b [2] = a [2] + 5;};

does not work as expected - array b remains unchanged.

1 Answer 1

4

Because you're passing by value and simply modifying the copied array, which has nothing to do with the outer b. You have to pass by reference:

auto f = [](const array<GLfloat, 4>& a, array<GLfloat, 4>& b) {b[2] = a[2] + 5;};
                                                       ^^^^

You should pass a by reference-to-const as well, to avoid the unnecessary copy.

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

Comments

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.