Solved

Callback function

Posted on 1999-01-11
4
242 Views
Last Modified: 2010-04-02
in one of my method i must use a callback function.
the functin is passed like a pointer, how i can use them
Register(void *CallbackFunction,char *name)
{
  i =  (CallbackFunction*)(name,Number);??
}
0
Comment
Question by:Zircona
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Accepted Solution

by:
AdrianBrown earned 100 total points
ID: 1181852
You need a pointer to a function like

void MyFunc(int a, char b, int c)
{
  // Whatever
  printf("hello");
}

void (Function *)(int, char, int);

void main(void)
{
  Function = &MyFunc

  // Call MyFunc
  Function(10, 3, 2);
}

I think ive got the brackets and address markers in the right place.  If this isnt correct or not what your asking let me know

Hope this helps

0
 
LVL 22

Expert Comment

by:nietod
ID: 1181853
For greater programmer ease and safety, you might want to use virtual functions instead of function pointers.  There is no need for funciton pointers in C++ (unless the project must interface with non-C++ code, like the OS.)
0
 
LVL 1

Expert Comment

by:shrif
ID: 1181854
I just want to echo wnat nietod has said.  For those of you who want to write more object oriented code, when you come across a need for a function pointer -- step back and think about the problem and you'll see that a virtual function will fit the bill very nicely.
0
 

Expert Comment

by:Sergio_Ravasio
ID: 13960956
OK, could you pls give me an example how do you write the AdrianBrown code (see on top of the page) by using virtual functions?
thanks in advance
Sergio
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 135
Compile GLUT with Visual Studio 2015 1 207
Error C2678: binary '!=': no operator found... 4 65
Installshield for Embarcadero EX 10.1 Berlin 4 75
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question