I'm having some issues working with c++ recently, its basically this:
Inside a function (lets say int main), I declared a variable Y = 5, and I have this lambda function that receives a value and adds up Y;
My problem is: I need to pass this lambda function to an already existent function, so it can be called inside the other function.
I tried a couple of things, but none of them worked as I intended (some not even worked):
double receives( double (*f)(double) )
{
return f(5);
}
int main()
{
int y = 5;
auto fun = [](double x) {
return x + y;
};
cout << receives(&fun);
return 0;
}
Another problem is that I cant change my receives function signature, the parameter must be double (*f)(double) because of the remainder of the code. I also need the lambda function to carry over the y value, without using additional parameters.
Anyone can help me on this?