[英]How do you write a function pointer that returns a function pointer without using typedefs?
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. 尽管使用typedef可能更明智,但我对没有typedef的语法感兴趣。
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 不使用typedef
您可以声明为
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
. 声明读为: funcPtr
是指向需要两个Type
参数的函数的指针,并返回一个指向需要Type
参数并返回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
. 声明为: func
是一个函数,它接受两个Type
参数,并返回一个指向接受Type
参数并返回Type
函数的指针 。
Now you can assign func
to funcPtr
现在您可以将func
分配给funcPtr
functPtr = func;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.