看板 Programming 關於我們 聯絡資訊
小弟有個關於指標陣列的疑問 書上說指標陣列常拿來做選單系統, 不同的選項會呼叫不同的function 今天如果code如下 // prototype void fun1 (int); void fun2 (int); void fun3 (int); // function pointer array void (*f[3]) (int) = {fun1, fun2, fun3}; 這樣是OK的 但是如果把fun2改成 void fun2 (int, int) 就會出現compile error (cannot convert from xxxxx) 也很明顯的是函式的signature不合 所以我的疑問是 難道要用function pointer做到選單功能 每個選單功能的回傳和接收的參數數目難道都要一樣嗎?這樣一點也不彈性 所以我想問, 請問有沒有什麼辦法可以解這個問題? 讓陣列裡面每個pointer都指到一個函式 而且那些函式也可以有不同的回傳和接收參數數目 感謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.109.227.99