Hi I am currently trying to create a library similar to the c++ vector library before running into a problem. I need a way to dynamically create a variable with the name of an int to save the new data e.g:
void loop() {
for (int i = 0; i < 10; i++) {
int /magic/ = 0;
}
}
then I need to read it again later
for (int i = 0; i < 10; i++) {
Serial.println(/magic/);
}
any help would be appreciated and if you use pointers could you briefly explain them
/magic/ is just the code i don't understand it takes the integer i want the name of the variable to be and turns it into something the compiler can read so if I wanted the contents of i to be the name of my variable the piece of code takes the input i and makes it a format that can be made the name of a variable.
sorry for my late response I exceeded my maximal number of posts.
If you wish to use that variable later on, from somewhere outside of loop(), you need to declare it as a global (ie, outside of any function, traditionally at the top of the sketch); if you're making a class, you make that variable one of the class members, and declare an instance of that class in the global scope.
You can't, within one block, declare a variable, and have it propagate to the global scope - you have to declare it within the global scope first.
what I want is to name of the variable to be the data stored in another variable so
int name = 30;
int /a way of naming it from the condense of int name/ = 0;
sorry for not being clear during the program I need to create integers with a name stored in another variable
so if i contains 30 i want to make the name of the variable 30 but without actually writing the number so
int i = 30
int some code to do with i = 0;
also can I address variables with the data stored in integers e.g.
int i = 30;
Serial.println("someCodeToDoWithI");
to say again i have the name i want to call the variable stored in a another variable and need to creat that variable using that name but I might't know what that name is.
to say again i have the name i want to call the variable stored in a another variable and need to creat that variable using that name but I might't know what that name is.
You keep saying that, but, at run time, when you want to create the variable with the name of another variable, that other variable does NOT have a name.
It sounds to me like the vector class is NOT the one that you need to be re-implementing. The dictionary class, with name and value pairs, is.
If you disagree, quit the hand-waving, and provide a concrete example.