Strings to Variable Names
-
I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team
-
I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team
I'm not sure if I understood you completely but in C++ there's no such association between a varaible name and a string, a variable name is merely a symbol by which you tell the compiler that you are about to request a block of memory, whereas a string is an array of characters. You cannot "convert" them into each other because they are totally different concepts.
-
I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team
Hum, I think I don't really understand you but why do you make so complicated ??? Why don't you just acces the array as normally like that: TCSpinEdit* Temp; for (int iCtr=0;iCtr<58;iCtr++) Temp = SpinnerArray[iCtr];
-
I am a professional, but unfortunately junior, developer, and I'm looking to do something that I thought I knew how to do. Now, I cannot recall how to do it, and I'm feeling... well, terribly ignorant. What is going on is I want to create an array of arrays - in specific, I'm making a pointer of pointers, actually. I want each of the pointers in the "array" to point at an object of the same type. I wanted to set up a for-loop to assign these. In other words, I have something like: TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++) the name of each of these objects starts out with CSpin followed by a number, from 1 to 58; so I need to point to CSpin1, then CSpin2, etc. Therefore, I need to generate a string, or whathave you, to designate each CSpin variable to each of the pointes in the array. And I realized I was unsure how to go about this. I started originally by using the string class; assign it as: string = "Cspin" + iCtr; But I realized I wasn't sure how to use the string to refer to a variable NAME. Any suggestions? Thanks! James A Beggs Microsoft MSN Mobile Component Test Team
You seem to be confused about what you really want - I try to give you an explanation, and maybe you can then decide if this was what you intended.: James A Beggs wrote:
TCSpinEdit ** SpinnerArray; SpinnerArray = new TCSpinEdit *[58]; for (int iCtr = 0; iCtr < 58; iCtr++)
So you have a pointer to an array of 58TCSpinEdit*
s. In your for-loop you need to initialize each of theTCSpinEdit*
0 to 57 with a pointer to aTCSpinEdit
:for (int iCtr = 0; iCtr < 58; iCtr++)
{
SpinnerArray[iCtr]= new TCSpinEdit( parameter );
{Your TCSpinners are now accessed as SpinnerArray[i], where i=0..57. If you need - for whatever reason - a association between your TCSpinners and some other data, e.g. a string, you might use a std::map < string, int > to store pairs of strings and indices into your SpinnerArray.
My opinions may have changed, but not the fact that I am right.