Firstly, I want to create a function inside main. Secondly, I want to pass this function as an argument to another function. Is it possible please?
For the first point, I know that it is possible using lambda functions or structures, as explained in the following link: Can we have functions inside functions in C++?
However, I did not manage to pass this function as an argument to another function.
More precisely, I want something like:
int main()
{
void add(int x, int y){cout<<x+y<<endl;}
int a = 1;
int b = 2;
apply_operator(add,a,b);
}
where apply_operator is defined in another file by:
void apply_operator(void (*operator)(int,int),int x,int y)
{
operator(x,y);
}