I'm trying to return a pointer to function without the use of typedef, but the compiler (gcc) is emitting a strange error, as if I could not do that kind of setting.
Remarks: With the use of typedef code works.
code:
void catch_and_return(void (*pf)(char*, char*, int&), char *name_one, char* name_two, int& number)(char*, char *, int&)
{
pf(name_one, name_two, number);
return pf;
}
Error:
'catch_and_return' declared as function returning a function
Can you explain to me why the compiler does not let me do this? Thank you!
Declare your function as the following:
void (*catch_and_return(void (*pf)(char*, char*, int&), char *name_one, char* name_two, int& number))(char*, char *, int&)
{
pf(name_one, name_two, number);
return pf;
}
The syntax for functions that returns functions is:
returned-function-return-type (* function-name (parameter-list) ) (function-to-return-parameter-list)
Note: This declarations can be cumbersome to understand at first sight, use typedef
whenever is possible
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