1. callback function call Relationship Diagram
In the first case, the main program can perform the callback function from execution to callback, or does not execute the callback function. The key is to check whether the host function has called the callback function. In the second case, the main program can perform the callback function from execution to callback, or does not execute the callback function. The key is to check whether the host function has called the callback function. The main program does not know when the host function will call the callback function. Because the calling function starts the thread, the main program does not have to worry about when the host function will call the callback function, the main program can be released to do its own thing.
1 sample code# Include <stdio. h> typedef void (* lpfunc) (void *, char *); // function pointer // The host function of the callback function, where the callback function is used, void getcallback (void * lpvoid, lpfunc callback) {callback (lpvoid, "test") ;}class A {public: A () {}; void outname (char szalarm []) {printf ("My name is % s/n", szalarm);} // callback function called by the host static void fcallback (void * lpvoid, char szalarm []) {A * P = (A *) (lpvoid); P-> outname (szalarm);} // call the external host function. After the test function calls the host function, test will no longer care about the host function // when to call the callback function, because at that time, the host function itself had void test () {getcallback (this, fcallback );}}; int main (void) {A;. test ();}