我可以在函数定义中使用函数typedef吗? [英] Can I use a function typedef in function definitions?
本文介绍了我可以在函数定义中使用函数typedef吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经定义:
typedef int FunkyFunc(int x);
现在,我希望能够在类型 FunkyFunc
(例如
Now, I would like to be able to use this typedef in the definition of functions of type FunkyFunc
, e.g.
FunkyFunc f {
return 2*x;
}
或
FunkyFunc f(int x) {
return 2*x;
}
或
FunkyFunc f(x) {
return 2*x;
}
我可以做与以上任何事情类似的事情吗?他们似乎都没有编译.
can I do something similar to any of the above? None of them seems to compile.
推荐答案
否.您可以使用typedef来声明一个函数:
No. You can use the typedef to declare a function:
FunkyFunc f;
但是函数定义必须使用函数样式声明符编写.
but a function definition must be written with a function-style declarator.
注意:在C ++中肯定是这种情况,并且我很确定C在这方面是相同的.但是如果您选择一种语言问问会更好,因为C和C ++之间可能会有显着差异,即使您可能会想到它们是相同的.
这篇关于我可以在函数定义中使用函数typedef吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文