anithar
June 3rd, 2002, 01:56 AM
What is a callback procedure in C++ terms ? How is it useful ?
|
Click to See Complete Forum and Search --> : callback procedure anithar June 3rd, 2002, 01:56 AM What is a callback procedure in C++ terms ? How is it useful ? proxima centaur June 3rd, 2002, 08:48 AM For a callback, you usually register through a function by passing the function pointer to the funciton you want to be called. Thereafter, the callback function is called when it is appropriate. See it as an event handler. curious June 3rd, 2002, 09:05 AM The WIN32 SDK SetTimer() function is a good example. Lets say you want to write a program that prints the cricket score every 5 minutes. You have writen a function PrintScore() for it .. but you want it to be called every 5 minutes. So you pass your function pointer to SetTimer(). SetTimer() will call PrintScore() every 5 minutes. PrintScore() is the call back function. JMS June 3rd, 2002, 03:44 PM Call backs are very useful in a method of programming called loose couppleing. This means you can have two classes / functions who's designers might have never known about each other and they can be dynamically configured to call one another without making a programming change. This concept becomes very powerful when used in conjunction with dll's where code can be added to an executeable without being recompiled. Callbacks and loose coupling allows a programmer to literally build building blocks which can be added, subtracted or modified extensively with a minumum of brawn but rather substituting brain. Example..... Using a transport class one could register variable classes which once modified would automajically transfer and refresh data across a wire. New transfer classes could be added dynamically through a dll interface and be almost limitelessly expandable. bernhard_r June 4th, 2002, 04:12 AM they are commonly used for functions which sort something (e.g. qsort of the runtime library..) because of the fact, that these functions can't know which of your objects is bigger, you can write a function (return e.g. false for bigger) and then the other function can sort it.. if you think that this concept is braindead or wrong.. the whole stl is based on a similar concept.. just that the coupling is very elegantly (and complicated at first) anithar June 6th, 2002, 08:59 AM Thank u all for the replies...got it now codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |