Functions to create functions?

Just wanted to know if its possible to create a program that can create functions at run-time? I don't think its possible but I can't find anywhere that gives a definite answer, I was woundering if there was a way around the rules.
Like if I use a template for creating them or some high class trick like that... or something like:
1
2
cin >> fName;
fName() = new fn();


I know its just wishful thinking but so is all my programming.
Last edited on
No, not exactly. Where exactly would you expect the code for this "created" function to come from?
Oh, sure it is. Self-modifying code (http://en.wikipedia.org/wiki/Self-modifying_code ). Not in C++, though. It doesn't have the kind of flexibility to allow modification of code space at run-time.

That syntax you have there (minus two parenthesis) is used to initialize pointers to a point to a new variable created in the heap.
Fair enough, C++ should add that feature.
I was thinking that the code would all come from the user and then store the function. Just a thought, woulda made some things easier.
Thanks for the info
You could implement a language to interpret a script at run-time.
Topic archived. No new replies allowed.