[英]How to declare an array of function pointers without using a typedef for the function pointer?
我向一位學習同事展示了如何使用函數指針以及如何使用它們的數組。 我放下以下代碼,以便他可以進行索引調度:
typedef void (*VoidFunction)();
VoidFunction functions[] =
{editProgramName,
editProgramLength,
editProgramCycles,
editProgramNumberOfSets,
editProgramEditSets,
editProgramSave,
editProgramCancel};
// now dispatch
functions[scroll.arrayFocusIndex]();
然后他問道......“如果沒有typedef怎么辦呢?” 在嘗試了似乎可能有用的各種事情后,我發現了這些,我沒有做任何線索。 我發現的所有谷歌點擊總是似乎使用typedef。 有沒有辦法在沒有函數指針的typedef的情況下進行內聯?
void (*functions[])() =
{editProgramName,
editProgramLength,
editProgramCycles,
editProgramNumberOfSets,
editProgramEditSets,
editProgramSave,
editProgramCancel};
// now dispatch
functions[scroll.arrayFocusIndex]();
這對我有用:
void a()
{
}
void b()
{
}
void (*functions[2])();
int main()
{
functions[0] = a;
functions[1] = b;
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.