I saw this, but it never specified how to declare a function pointer that returns a pointer-to-a-function (it simply defined how to create a function returning a function pointer).
While it would probably be wiser to use typedefs, I am interested in the syntax to accomplish this without typedefs.
This is the closest I got:
struct function_hash_table {
unsigned int(*(*getFunction)(Type, Type, Type))( char *name );
}
(What type actually is is rather irrelevant to this question).
But, when I try to call it like this:
hash_table.getFunction( "Test" );
I get errors for too few parameters and wrong parameter types.
To Clarify:
unsigned int(*hash_get_function(Type, Type, Type))(char *name)
Works good for actual functions and explained in the link. However, how am I suppose to declare a function pointer that refers to such a definition?
how to declare a function pointer that returns a pointer-to-a-function
Without using typedef
you can declare as
Type (* (*funcPtr)(Type, Type) ) (Type);
Declaration read as: funcPtr
is a pointer to a function that expects two arguments of type Type
and returns a pointer to a function that expects an argument of type Type
and returns Type
.
If you wan to declare a function that return a pointer then
Type (* func(Type, Type) ) (Type);
Declaration read as: func
is a function that accepts two parameters of type Type
and returns a pointer to function that accepts an argument of type Type
and returns Type
.
Now you can assign func
to funcPtr
functPtr = func;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments