[ create a new paste ] login | about

Link: http://codepad.org/s38L9tUr    [ raw code | fork ]

Plain Text, pasted on Nov 3:
// D
  1 auto return_local()
  2 {
  3     int x = 10;
  4     int delegate () f = { return x; };
  5     x = 15;
  6     return f;
  7 }
  8 
  9 void main()
 10 {
 11     import std.stdio;
 12     writeln(return_local()());
 13 }
// Output: 15

// C++
  1 #include <iostream>
  2 #include <functional>
  3 
  4 std::function<int()> return_local()
  5 {
  6     int x = 10;
  7     auto f = [=](){ return x; };
  8     x = 15;
  9     return f;
 10 }
 11 
 12 int main()
 13 {   
 14     std::cout << return_local()() << std::endl;
 15     return 0;
 16 }
// Output : 10


Create a new paste based on this one


Comments: