I would like to assign a pointer to a lambda function, in which the lambda function is taking variables passed by reference, not by value.
int main() {
// what I can do, but not quite what I want
auto funcy = [](const double i ) {
std:: cout << "this is i: " << i << std::endl;
};
void(*lptr)(double); // OK
lptr = funcy;
lptr(1);
// TODO: make a variable that points to this lambda work
auto funcy2 = [](const double &i ) {
std:: cout << "this is i: " << i << std::endl;
};
void(*lptr2)(double *); // BROKE
lptr2 = funcy2;
lptr2(1);
return 0;
}
Is it possible to do this?
Thanks for your time.
Edit: This post is different from Passing capturing lambda as function pointer because I have no idea what that one is saying.