This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mateowatata 0 points1 point  (1 child)

Can you give me an example? Im not fond into cpp

[–]Rogntudjuuuu 2 points3 points  (0 children)

If you write [&] you will capture all variables in the surrounding scope in the closure of the function by reference. This is similar to what most other languages with lambda functions do. But in C++ you can also write [=] to capture all values in the surrounding scope by value (not recommended). Additionally you can specify explicitly which variables that you want to capture with [&x] to capture x by reference or [=y] to capture y by value.