KirAsh4:
It is what it is.
Isn't everything?
KirAsh4:
I have two variables:
long chicken_abc[8];
long chicken_def[8];
Then I have a routine 'chicken_legs()' that gets called like so:
chicken_legs('abc');
OR:
chicken_legs('def');
Based on that, within the 'chicken_legs()' routine, I need to figure out which variable to use based on what was passed.
...
There are ways to do this with other languages, so I'm curious whether it can be done here as well.
Yes, well you are thinking of interpreted languages, like Lua, Perl etc. Those languages process the source at runtime, or otherwise give access to the compiler symbol table. For example, in Lua you could that by constructing a string value to key into the global environment table, thus accessing any global variable by a name computed at run time.
However C++ doesn't work like that. The code uploaded to the processor has no memory of the variable names used to generate it, and thus no mechanism for accessing different variables by name.
Now you can achieve the end result (it isn't totally clear what that is, you are giving examples of how you want to achieve something, not what the something is).
I think personally that passing strings down to functions and using them as selectors is a bit slow and unwieldy on a microprocessor. Any objection to passing numbers?
Judging by the way you are writing your code, you are a bit new to C++. Rather than trying to fight it and make variable names that are computed at runtime, I would read up a bit more on what the language offers. No insult intended, but sometimes people who are new to a language try to do things in it that are better suited to other languages.
This isn't a real problem versus a not-so-real problem situation.
The "real" problem isn't to change the way you access variables at run-time, right? The real problem is to control a robot, or a heating system, or make an access-control system, or fly a rocket to the moon (etc.). Perhaps if you explain what you want to achieve (leaving the language aside for one minute) we could offer more useful advice.