Karthikeyan M wrote:
> Hi All,
>
> I was just wondering, is it possible to name a variable during
> runtime???
>
> (don't bite your teeth. I know it's a dumb Q :-) )
>
> Thanks & Regards,
> Karthikeyan M
Not probably in the sense that you are thinking, BUT you could use a
hash to store a number of "variables":
BString TestVar;
int MyValue;
BasicHash<int> MyHash;
TestVar = "NamedVar";
MyHash.Insert(TestVar, 500);
MyHash.Insert(TestVar, 502);
if (MyHash.Find(MyValue, TestVar))
{
printf("%i\n", MyValue);
}
Outputs: 502
I realize none of the above will work anywhere except my library
(actually, it won't even work there). I was just giving you an idea of
how it might work. In essence, you are creating name-value pairs. The
name maps to a value. In this case, an integer. But you could define a
class/struct that stores a generic data type. Similar to PHP and other
scripting languages. Although, BString _IS_ decent enough for a whole
slew of data types. A STL map might also work in place of a hash.
That's the closest you can really come to variables at runtime. And NOT
a dumb question. If the concept is good enough for developing a major
scripting language like PHP, then that means it probably isn't exactly
something taught in class. The example above is very basic compared to
the code used in PHP.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* VerifyMyPC 2.3
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.
Free for personal use, $10 otherwise.
http://www.CubicleSoft.com/VerifyMyPC/