Search code examples
c++function-declaration

C++ pointer to function declaration syntax


What is the difference between the two declarations in case of foo's arguments? The syntax in the second one is familiar to me and declares a pointer to function. Are both declarations fully equivalent?

void foo(int(int));
void foo(int(*)(int));

Solution

  • They are equivalent as long as int(int) and int(*)(int) are used in function parameter lists. In function parameter list the int(int) is automatically adjusted by the language to mean int(*)(int).

    It is the same adjustment mechanism that makes int [] parameter declaration equivalent to int * parameter declaration.

    Outside of this specific context int(int) and int(*)(int) mean two different things.