如何创建函数指针的typedef [英] How to create a typedef for function pointers
本文介绍了如何创建函数指针的typedef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这将是更容易使用的函数指针,如果我创建了一个函数指针的typedef,但我似乎得到自己绊倒了一些语法或有关的typedef函数指针的用法什么的,我可以使用一些帮助。
I think it would be easier to use function pointers if I created a typedef for a function pointer, but I seem to be getting myself tripped up on some syntax or usage or something about typedef for function pointers, and I could use some help.
我已经有了
int foo(int i){ return i + 1;}
typedef <???> g;
int hvar;
hvar = g(3)
这基本上就是我试图完成我是一个相当新的C程序员,这是我扔太多。什么代替&LT; ???&GT;
推荐答案
您的问题目前尚不清楚,但我想你可能想是这样的:
Your question isn't clear, but I think you might want something like this:
int foo(int i){ return i + 1;}
typedef int (*g)(int); // Declare typedef
g func = &foo; // Define function-pointer variable, and initialise
int hvar = func(3); // Call function through pointer
这篇关于如何创建函数指针的typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文