So Lets say I have a function:
void foo (int i){
cout << "argument is: " << i << endl;
}
And I am passing this function to:
void function1 (void(callback)(int), int arg){
callback(arg);
}
void function2 (void(*callback)(int), int arg){
callback(arg);
}
are these two functions identical? Is there any difference between the two?
The rule is that in a function's parameter list, a parameter declared to have a function type is adjusted to have pointer to function type (similarly, and probably more well-known, a parameter declared to have type "array of T" is adjusted to have type "pointer to T". Redundant parentheses in declarators are allowed, but ignored.
Thus, in
void function1 (void(callback)(int), int arg);
void function2 (void (*callback)(int), int arg);
void function3 (void callback(int), int arg);
The first parameter of those three functions have exactly the same type - "pointer to function of (int) returning void".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With