简体   繁体   English

如何编写不使用typedefs即可返回函数指针的函数指针?

[英]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.

相关问题 定义一个返回函数指针的函数,该函数指针也返回一个没有typedef的函数指针 - Defining a function which returns a function pointer which also returns a function pointer without typedefs 如何在不使用C中的typedef的情况下声明一个返回指向函数的函数的函数,该函数返回函数指针? - How do I declare a function that returns a pointer to a function that returns a function pointer without using a typedef in C? 如何声明一个指向函数的指针,该函数返回一个指向C / C ++中int值数组的指针? - How do you declare a pointer to a function that returns a pointer to an array of int values in C / C++? 如何使用 function 指针编写 function 的名称? - How to write the name of a function using a function pointer? 如何定义一个指向函数的指针,该函数返回指向函数的指针 - how to define a pointer to function that returns a pointer to function 如何声明一个返回函数指针的函数指针 - How to declare a function pointer that returns a function pointer 如何使用gets()函数直接写指针? - How to write to pointer directly using gets() function? 如何编写一个 function,它需要一行文本,并将每个单词保存在指向 char 的指针中并返回该指针 - How to write a function that takes a line o text, and saves each word in a pointer to pointer to char and returns that pointer 函数将指针返回到函数,将指针返回到函数 - Function returns pointer to function that returns pointer to function 如何声明一个返回函数指针的函数? - How do I declare a function that returns a function pointer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM