int fu1(int v){
int z=v+2;
return z;
}
int fu2(int fu1(int v)){
int g=fu1(int v)+2;
return g;
}
int main(){
int a=2;
cout<<fu2(a);
return 0;
}
Output:
1
2
3
In function 'int fu2(int (*)(int))':
Line 7: error: expected primary-expression before 'int'
compilation
Are you trying to have fu2 take different functions at runtime? If not, just have it take a normal integer parameter. You seem to have some misconceptions here.
If you want to pass a function, look up std::function . That's not necessary for what you're trying to do however.
From what I can tell you'd be better off having fu2 just take regular int as argument, then when you call it inside main let fu1 return the value being passed in. Pretty sure L B was trying to tell you the same thing.
You're not explaining very clearly what it is you want to do. I can see two possibilities:
1) You want to define fu2 to take an integer argument. When you call fu2, you want to pass in as that argument, the result of a call to fu1.
2) You want to define fu2 such that, inside fu2, it calls another function. You want it to be able to call different functions at different times, so you're passing in as an argument the identity of the function you want it to call. So, on an occasion where you want fu2 to call fu1, the you call fu2 and pass in a pointer to fu1 so that, inside fu2, it calls fu1.