Hi there!
Could anyone tell me how to return a function back to main()??
Cheers
ps i have looked on the boards......
Hi there!
Could anyone tell me how to return a function back to main()??
Cheers
ps i have looked on the boards......
Use a function pointer:
-PreludeCode:#include <iostream> typedef void (*pf)(); void print() { std::cout<<"Now we're havin fun!\n"; } pf func() { return &print; } int main() { func()(); // How's this for wacky syntax? :p return 0; }
My best code is written with the delete key.
Then, how's this?
Code:void (*func())() { return &print; }
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
You can't return functions in c. You can in scheme and some other languages but not in c++.
There's stuft you can do such as returning function pointers
or function objects which are classes like
Code:class C { public: int operator()(int n) const { printf("n = %d\n"); } };