|
-
June 3rd, 2002, 01:56 AM
#1
callback procedure
What is a callback procedure in C++ terms ? How is it useful ?
-
June 3rd, 2002, 08:48 AM
#2
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.
Martin Breton
3D vision software developer and system integrator.
-
June 3rd, 2002, 09:05 AM
#3
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.
-
June 3rd, 2002, 03:44 PM
#4
call backs
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.
-
June 4th, 2002, 04:12 AM
#5
another usage..
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)
-
June 6th, 2002, 08:59 AM
#6
Thank u all for the replies...got it now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|