[問題] 請教 Function Pointer 的觀念
看紅螞蟻那本書看到Function Point 可是看不太懂 ( P 435 第五版 )
程式的宣告那段是這樣的
void selectionSort( int work[], const int size, bool (*compare)( int, int ) )
後面那段 bool (*compare)( int, int ) 看不懂
為何要這樣做? 也不懂什麼意思-。-
為什麼不能 bool (*compare) 就好??
為什麼不能 bool *compare( int, int ) ??
為什麼不能 bool compare( int, int ) ??
裡面的一段敘述是這樣的
The text (*compare) indicates the name of the pointer to the function
( the * indicates that parameter compare is a pointer ).
Parentheses are needed around *compare to indicate that compare is a
pointer to a function. If we had not included the parentheses, the declaration
would have been bool *compare( int, int ) which declares a function
that receives two integers as parameters and returns a pointer to a bool value
可以詳細的說明嗎,還有何時需要用 Function pointer,感激不盡^^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.203.138
→
03/06 23:53, , 1F
03/06 23:53, 1F
推
03/07 00:09, , 2F
03/07 00:09, 2F
→
03/07 00:11, , 3F
03/07 00:11, 3F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 4 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章