I am confused by the form of parameters for function pointers. The following two:
int fun(int (*g)())
{
cout << g() << endl;
}
int fun(int g())
{
cout << g() << endl;
}
Both these two definitions work well. But as you have noticed, there are some differences in the prototypes of these two functions:
- the first one takes parameter
int (*g)(), - while the second takes parameter
int g().
My question is are there any difference between them?
In the second case, the function type adjusts to become pointer-to-function-type, which makes the both function identical.
The C++03 Standard says in §13.1/3,
It’s same as with array to pointer adjustement, with which we’re more familiar:
All are same!
You can a detail answer by me here: