language: C++11 (gcc-4.7.2)
date: 192 days 17 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <functional>
#include <iostream>
using namespace std;
 
const function<void()>* pointer;
 
void a(const function<void()> & f)
{
    pointer = &f;
}
 
void b()
{
    (*pointer)();
}
 
int main()
{
    int value = 1;
    std::cout << value << std::endl;
 
    // 1: this works    
    function<void()> f = [&] () { std::cout << value << std::endl; };
    a(f);
 
    // 2: this doesn't
    a([&] () { std::cout << value << std::endl; });
    //c();
    char data[1024];
    for (int i = 0; i < 1024; i++)
        data[i] = i % 4; 
 
    b();
 
    return 0;
}