【发布时间】:2012-06-04 06:28:23
【问题描述】:
朋友们好,
How can I use an array of function pointers?
如果我们看到上面的链接,它会告诉我们函数指针是如何工作的。
现在的问题是我为什么要选择函数指针?
为什么不能直接使用函数调用?
使用函数指针有什么好处?
例如
enum{a, b, c};
void A();
void B();
void C();
void (*fun[3])() = {A, B, C};
Now when I need to call a function I am doing like,
fun[a](); // This calls function A
// And so on...
在函数调用中也可以这样做
比如当我需要调用函数 A、B 或 C 时。 直接点赞就可以了
A();
B();
or
C();
那为什么是function pointer?
【问题讨论】:
-
我不知道为什么我的问题有两个反对票。但我知道一件事,这并不意味着如果你知道每个人都应该知道的事情。无论如何,只要我的疑虑得到消除,+ve 或 -ve 投票都无关紧要。
标签: c function function-pointers