Advertisement

C++ Pointer Functions

Started by January 23, 2001 11:19 PM
4 comments, last by Galileo430 24 years ago
I was just wondering how you would get a pointer to a function in C++. Let me clarify:
  

int main()
{
return 0;
}

int AFunction() //Want The Pointer To This Function

{
return 0;
}
  
I checked my MSDN cd. Can''t find it. Anyone know how?
------------------------------------------------------------I wrote the best video game ever, then I woke up...
int (*func)();

func = AFunction;

.travois.
Advertisement
All I get is 0x000000.

I can''t get it to put the memory address in the pointer function.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
thats weird, what TV posted is accurate. make sure the arg signature and return tryp matches, ie:

  float MyFunc(int x, bool b){...}typedef float(*FuncPtr)(int,bool);void main(){    FuncPtr func = MyFunc;    func(0, true);}  
Make sure you don''t have:

func = AFunction(); // will execute AFunction

but

func = AFunction; // will take the address of AFunction
Got it.. Thank you.
------------------------------------------------------------I wrote the best video game ever, then I woke up...

This topic is closed to new replies.

Advertisement