C ++: Learning callback Functions
Callback Function: a function called using a function pointer. The callback function is not called by the implementer, but is passed in to trigger the call under special conditions or status.
For example, when a Custom button control is clicked, a click event is triggered to call a specified function.
Note: The callback function inherits from the C language. In C ++, the callback function is used only when an interface is established with C code or when an existing callback interface is used,
In addition, the virtual method or function simulation should be used in C ++, rather than the callback function.
Callback Function
1 // m_callback is the callback function, and setCallback is used to pass in the specified function; 2 class CMenuButton: public CSDLGameObj 3 {4 public: 5 CMenuButton (): m_callback (NULL), m_bRelease (TRUE) {}; 6 void load (CLoaderParam * pParam); 7 void Draw (); 8 void Update (); 9 void Clean (); 10 void setCallback (void (* callback) () {m_callback = callback;} 11 private: 12 void (* m_callback) (); 13 BOOL m_bRelease; 14 };