Advertisement
homer512

lambda pointer capture

Sep 8th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. int main()
  4. {
  5.   auto a = []() { return new char; };
  6.   char* b = a();
  7.   std::printf("%p\n", b); // -> "0x..."
  8.   auto c = [b]() { std::printf("%p\n", b); };
  9.   c(); // -> "0x..."
  10.   auto d = [&b]() { delete b; b = NULL; };
  11.   d();
  12.   std::printf("%p\n", b); // -> "(nil)"
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement