Given the following typedef function pointer:
typedef void(*vfp)();
We can certainly point to a void function as follows:
string s = "Gordon Freeman: Lambdas have no half-lives.";
void f() {
cout << s;
}
int main(int argc, char **argv)
{
vfp p;
p = f;
p();
}
But how can I point to a lambda expression?
typedef void(*vfp)();
int main(int argc, char **argv)
{
string s = "Gordon Freeman: Lambdas have no half-lives.";
vfp p;
p = [&s]()->void{cout<<s;}; // Error, lambdas do not return "function objects" as in Python.
p();
}
Error:
cannot convert 'main(int, char**)::__lambda0' to 'vfp {aka void (*)()}' in assignment.
So, if I can't point to an anonymous lambda function in the same way I can point to a function, they are not functions (And they should be. If they're not, why they're not?)