Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
lambda-by-reference.cpp
Go to the documentation of this file.
1 
7 #include <iostream>
8 
9 int main()
10 {
11  std::string suffix = "\n";
12 
13  auto lambda1 = [&suffix](const std::string& string) -> std::string { return string + suffix; };
14 
15  std::string ex = "Hello World";
16  std::cout << lambda1(ex);
17  suffix = "ab\n";
18  std::cout << lambda1(ex); // suffix has changed in in the lambda
19  return 0;
20 }
int main()
Demonstration of a lambda, with a capture taken by reference.