Callback style in C ++

Source: Internet
Author: User
1. Callback style in C ++. In the C era, when an asynchronous call is made, if the other party wants to notify itself of the execution result, it generally registers a function pointer during the call. After the other party completes the execution, execute the function pointed to by the function pointer to reach the wood of the notification. In C ++, an interface is used to replace the function pointer. For example
Class   Delegate
 
{
 
Public:
Virtual Void Response(STD::String& Resultstr) = 0;
 
};
Class Calldelegate :Public Delegate
 
{
 
Public:
 
Reponse ()
{
 
STD: Cout <resultstr <STD: Endl;
 
}
 
};

When an asynchronous call is made, the other party only knows the delegate and sends a calldelegate pointer to the other party. After the other party completes the execution, it calls the response function to complete the asynchronous notification execution result.

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.