Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created December 1, 2012 19:25
Show Gist options
  • Select an option

  • Save ElemarJR/4184340 to your computer and use it in GitHub Desktop.

Select an option

Save ElemarJR/4184340 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
int var = 5;
cout << "(before) var = " << var << endl;
auto byvalue = [=]
{
// var = 4; resulta em erro de compilação
cout << "(byvalue) var = " << var << endl;
};
auto byreference = [&]
{
var = 3;
cout << "(byreference) var = " << var << endl;
};
byvalue();
byreference();
cout << "(after) var = " << var << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment