"muffinman" <mu**********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello,
I try to convert a string (char[] or string or CString, etc) into
an executable function.
For example :
char sample[20] = "cout << \"sample\"";
char setColor[30] = "glColor3f(1.0f, 1.0f, 0.0f);"
execute(sample); // my wish is to do this!
execute(setColor); // and also this!
then I can run the string.
I am trying to write a game console without directInput. I want to
execute any strings, without switch or if comparisons...
Thank you
This is actually very high level, and C++ does not support this type of
programming. It's called reflection, since it's a feature to let a
programming language sort of "see itself". Also called meta programming for
the same reason.
You can do those things in C# (and Java I think), since the run time code
("MS intermediate language" or "Java bytecode") contains information on the
names of classes and their methods and so on.
When you compile a C++ program you end up with assembly, and all that sort
of information will not be available at run time.
Actually, to some degree, you can use a few of the features of reflection in
C++ if you compile your program with the RTTI switch turned on, but your
compiler must support this. And it does not allow full reflection, it just
allows you to do type checking at run time (Run Time Type Information).
-M