Premise: this question is just out of curiosity, I don't need to use this knowledge, therefore answers like "you don't need to do it" or "just use auto" are invalid. This is for science
The code below compile:
#include <iostream>
using namespace std;
int(*myFunction(int b))(int a)
{
int(*f)(int a) = [](int a) { int myVariable = a ; return ++myVariable; };
return f;
}
int main()
{
while (true){
cout << myFunction(5)(12);
}
}
Now if I change the lambda to capture b, the code doesn't compile anymore, code below:
int(*myFunction(int b))(int a)
{
int(*f)(int a) = [b](int a) { int myVariable = a + b; return ++myVariable; };
return f;
}
so my question is, what does the lambda type being assigned to "f" when I add the capture changes into?
How would you re-write "int(*f)(int a)" such that it compiles when there is that capture of "b"? (no auto, typedef, using or other tricks allowed, I want to see the ugly form )