C ++: Learning callback Functions

Source: Internet
Author: User

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 };

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.