這是一個回調函數的這部分,但我無法弄清楚這部分是如何工作的任何人都可以解釋我的代碼
如果(cb_onPress){cb_onPress(*此); } //觸發onPress事件
class Button;
typedef void (*buttonEventHandler)(Button&);
class Button {
public:
//code
private:
//code
buttonEventHandler cb_onPress;
};
void Button::process(void)
{
//code
if (cb_onPress) { cb_onPress(*this); } //fire the onPress event
}
void Button::pressHandler(buttonEventHandler handler)
{
cb_onPress = handler;
}
對於我自己的啓示......它不應該是(* cb_onPress)(*此)嗎?我試了兩次,並沒有得到任何抱怨,因爲他們兩個都用g ++ – jsantander
@jsantander AFAIK這兩個是相同的。我選擇較少的冗長選項。 – juanchopanza