callback function: A function that is called through a function pointer . When a function pointer is passed as a parameter, and the pointer is used to invoke the function it points to, we say this is a callback function.
A callback function is not called directly by the implementation method of the function, but is invoked by another party when a particular event or condition occurs, and is used to respond to the event or condition.
The callback function is a bit like a BP machine: Tell someone the number, call you when it has something
Callback is used for inter-layer collaboration, the upper layer of the function is installed on the lower level, this function is a callback, and the lower class triggers a callback under certain conditions, for example, as a driver, is a bottom, he received a data, in addition to the completion of this layer of processing work, will also be a callback to the upper application layer for further processing This is common in hierarchical data communication.
In fact, callbacks and APIs are very close, and their commonalities are functions that are called across layers. But the difference is that the API is the lower level of the call to the upper layer, generally this function is known to the upper level, and the reverse is the opposite, he is the upper level to provide to the bottom of the call , for the lower layer he is unknown, must be installed by the high-level, This installation function is actually a low-level API, the post-installation low-level does not know the name of the callback, but it through a function pointer to save the callback, when it is necessary to call, simply reference the function pointer and related parameter pointers. In fact: The callback is the function written in the upper layer, the lower layer through a function pointer to save the function, at the trigger of an event, the lower level through the function pointer to call the upper function.
Member methods, also known as instance methods, are static methods, also known as class methods
Summary of C + + selection questions (Callback function | | class method (instance method) | | )