lukeg
lukeg

Reputation: 4399

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));

Upvotes: 6

Views: 161

Answers (1)

AnT stands with Russia
AnT stands with Russia

Reputation: 320401

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.

Upvotes: 7

Related Questions