Last active
July 27, 2017 11:30
-
-
Save odeblic/ddc3cfe265fdfc8edbc0bd4c8be35c49 to your computer and use it in GitHub Desktop.
How capture work with lambda functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main(void) | |
{ | |
int a = 1001; | |
long double b = 3.1415926; | |
char c = 'A'; | |
std::string d = "I like C"; | |
std::cout << "a: " << a << std::endl; | |
std::cout << "b: " << b << std::endl; | |
std::cout << "c: " << c << std::endl; | |
std::cout << "d: " << d << std::endl; | |
auto f = [&a, &b, &c, d]() | |
{ | |
a++; | |
b *= 2; | |
c++; | |
//d += "++"; | |
}; | |
f(); | |
std::cout << "------------------" << std::endl; | |
std::cout << "a: " << a << std::endl; | |
std::cout << "b: " << b << std::endl; | |
std::cout << "c: " << c << std::endl; | |
std::cout << "d: " << d << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment