作者jimmy2266 (2266)
看板C_and_CPP
标题[问题] 请教 Function Pointer 的观念
时间Fri Mar 6 23:38:07 2009
看红蚂蚁那本书看到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
1F:→ james732:有一个指标,它指向一种函式:两个int参数,回传bool 03/06 23:53
2F:推 stonehomelaa:那本书的例子就是其中一个使用时机呀 03/07 00:09
3F:→ stonehomelaa:在执行时才决定是大->小或是小->大排序 03/07 00:11