This is actually a two part question, one being generating field-level variables inside of a function and the other being how to generate new variable names.
So below, say I have a string called str and an int n. I want to combine str (str literally, not the name of the string) and the value of n to create a new string, say str0, str1, etc. Now, I figured I could do this by using a print function to generate code, but I don't want to do it that way.
The other question would be how to generate field level variables (not static, but variables that only exist for that particular instance) within a subroutine of the class.
So below, say I have a string called str and an int n. I want to combine str (str literally, not the name of the string) and the value of n to create a new string, say str0, str1, etc. Now, I figured I could do this by using a print function to generate code, but I don't want to do it that way.
The other question would be how to generate field level variables (not static, but variables that only exist for that particular instance) within a subroutine of the class.
class VarGen { int n; string varname; string gen () { string strn; //code to convert n to a string called strn; //combine varname and strn to generate a new string ?? //Also, code to generate a field level variable, something like "field int q;" return //generated string name } } vg; int main() { vg.n = 0; vg.string = "hello"; vg.gen(); return 0; }