Skip to content

Instantly share code, notes, and snippets.

@odeblic
Last active July 27, 2017 11:30
Show Gist options
  • Save odeblic/ddc3cfe265fdfc8edbc0bd4c8be35c49 to your computer and use it in GitHub Desktop.
Save odeblic/ddc3cfe265fdfc8edbc0bd4c8be35c49 to your computer and use it in GitHub Desktop.
How capture work with lambda functions
#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