Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What is callback function

Reply
Thread Tools

What is callback function

 
 
PengYu.UT@gmail.com
Guest
Posts: n/a
 
      06-07-2005
Hi,

Would you tell me what callback function is used? Why we need it? I
searched the web. But most webpages only mention that how to use it but
not why to use it.

Best wishes,
Peng

 
Reply With Quote
 
 
 
 
John Carson
Guest
Posts: n/a
 
      06-07-2005
<> wrote in message
news: ups.com
> Hi,
>
> Would you tell me what callback function is used? Why we need it? I
> searched the web. But most webpages only mention that how to use it
> but not why to use it.
>
> Best wishes,
> Peng


A callback function is a function that is passed to another function (in the
form of a pointer to the callback function) so that the second function can
call it. This is simply of way of making the second function more flexible
without the second function needing to know a lot of stuff. By passing
different callback functions, you can get different behaviour (different
comparison rules, different formatting, different whatever). Nowadays it is
more common in C++ to use function objects for this purpose rather than
functions.

--
John Carson

 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      06-07-2005
<> wrote:

> Would you tell me what callback function is used? Why we need it? I
> searched the web. But most webpages only mention that how to use it but
> not why to use it.


qsort() and bsearch() in <cstdlib> both use it which gives a couple of nice
tangible examples. It allows qsort to sort an array of pretty much anything:
char, int, double, a particular field within a struct, .... . Note that
that code pre-dates templates in C++. For a C++ example, consider the
evaluation of a definite integral using Simpson's rule or some such. A
callback function providing f(x) can be provided for the equation being
evaluated.


 
Reply With Quote
 
Kyle Kolander
Guest
Posts: n/a
 
      06-07-2005

<> wrote in message
news: ups.com...
> Hi,
>
> Would you tell me what callback function is used? Why we need it? I
> searched the web. But most webpages only mention that how to use it but
> not why to use it.
>
> Best wishes,
> Peng
>


I'd also say that callback functions can be used for updates, sort of like
hooking into another function. For example, consider a function that
downloads files using http. Your application may want to display progress
to the user. You could pass a callback function (display progress) into the
download function so that it calls your display function everytime it reads
from the socket. At least that is my understanding...

Kyle


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to deal with calling a member function from a static callback Ctype function Angus C++ 3 03-01-2009 11:43 PM
Assigning a member function to signal callback function pointer Ramesh C++ 11 12-27-2008 08:36 AM
How do I create a function in my library for passing user callback function Angus C Programming 32 04-15-2008 02:28 PM
can a class member function be used as a callback function? JDT C++ 6 03-29-2007 12:45 PM
Howto: Class member function as callback function for dialog box prettysmurfed C++ 6 07-22-2003 06:17 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57