Call Back function

Call Back function

Call Back function

A callback is a callable that is accepted by a class or function and is used to alter the logic in use based on that callback.

 Writing generic code that is independent of the logic in the called function and can be reused with multiple callbacks is one reason to utilise callbacks.




Implementation of callback function








Two functions fun1 and fun2 are defined 2 pointers ptr1 and ptr2 pointing to the functions fun1 and fun2 resp. are created A callback function parent is declared which takes two parameter   that are the pointers to the functions fun1 and fun2 a function call is made to this call back function passing two argument ptr1 and ptr2. This call back functions calls both the functions separately using the pointer pointing  to them. The functions fun1 and fun2gets executed when they are called by parent function.