Can I create a reference to a function, as with a variable?
If not, can I do the same thing in another way?
This is a discussion on Function reference within the C++ Programming forums, part of the General Programming Boards category; Can I create a reference to a function, as with a variable? If not, can I do the same thing ...
Can I create a reference to a function, as with a variable?
If not, can I do the same thing in another way?
Do you mean a function pointer?Code:#include <stdio.h> typedef void (*vpfn) (void); void sayHi (void); void sayBye (void); int main (void) { vpfn myFn = sayHi; // NOT myFn = sayHi(); myFn(); printf ("And...\n"); myFn = sayBye; myFn(); return 0; } void sayHi (void) { printf ("Hi!\n"); return; } void sayBye (void) { printf ("Bye!\n"); return; }Or if you mean something else, could you describe a bit more what you want to do?Code::!a.out Hi! And... Bye!
Callou collei we'll code the way
Of prime numbers and pings!