SGi wrote:
Is there any way of getting a variable name from a cstring?
For example, intArray[1] = string_to_var("intVar_1"); something like this.
C++ does not support run-time introspection over variable names.
Consequently, compilers do not even construct any run-time information
which could implement that (other than maybe debugging info). When a
program is compiled and linked, most of the identifiers used in its
source code simply disappear. In an environment where there is no
further dynamic linkage, the result may simply be a machine language
executable containing no symbols whatsoever.
What you can do is create your own dictionary data structure (perhaps
using std::map or whatever) which associates strings, which serve as
names, with pointers or references to objects.
Then given some object which is known as Var1 in the source code, you
could create an entry in this map under the string "Var1" which points
to that same object.
variableMap["Var1"] = Var1; // reference is taken