I’m trying to compile the following program:
#include<functional>
#include<iostream>
int main(int argc, char* argv[], char* env[]) {
std::function<int(int, int)> f = [i, &j] { return i + j; };
std::cout << f(5, 5);
}
Why do I get the following error:
a.cc:17:3: error: \u2018function\u2019 is not a member of \u2018std\u2019
Even if I replace it with “auto” the compiler complains that “f” doesn’t name a type. I tried with GCC 4.4.3 and 4.6.2.
That is wrong syntax.
What you actually want to write is this:
Or if you want to use
auto, then:Use
-std=c++0xoption with gcc-4.6.2 to compile this code.