"The Directive" <th***********@hotmail.com> wrote in message
news:84**************************@posting.google.c om
Does C++ support dynamic programming? I hope I'm using the correct
term. I want to write code that can dynamically rewrite itself! I want
to dynamically create functions and call them and etc. If not, are
there any plans to add support for it in the future? What other
popular programming languages support dynamic programming? [Email me
privately for the last question so that people will not complain that
it's out of context.]
If you mean does C++ allow you to generate functions on the fly that are
identical to those produced at compile time, then the answer is no. C++ can,
however, be used to create an interpreter, i.e., a program that will allow
you to type in functions at runtime and will store and execute those
functions. Writing such a program involves some work, however (how much work
depends on the range of possible functions you wish to support).
Any function that you might write will be built up from basic operations
(built in operators like + as well as predefined functions like sin and
cos). Accordingly, an interpreter basically consists of a pre-written
all-purpose function that calls basic operations as needed by the function
that the user specifies at run-time (in the simplest case, it may involve a
switch statement that executes different operations depending on which
operation has been specified at run-time). For a simple illustration of how
this is done, look at the calculator program in Ch 6 (including exercise 20)
of Stroustrup's TC++PL.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)