Question about multiple type arrays
I'm using C++ (gcc) and want to know if there's a way to do something similar to what I can do in VB.NET:
dim arrData as Dictionary(typeof String, typeof Object)
In other words, it is a key/value pair array that you can just arrData.Add(key, value) and it adds it. I would be willing to even write such.
The thing is, the key is string (a name of the key) but the value can be of any type. It might be a string, a date, an int, long, double, who knows.
Is there a way in C++ to do this, have different types in an array? Or if not, then maybe I could put everything as string and have a 3rd parameter like:
arrData.Add(key, value, value_type);
Where the key, value and value_type are all strings but the value_type would denote what the type of the value should be, and then one can convert it?
Or is there a better way?
The thing you're after in C++ is called a map (an
associative array). Whether you can stick anything
into the value bit depends on whether all sorts of
anything can be cast to something that's of the same
type ... in other words, if you define a class my_object
which you can stick integers, strings or bitmaps into,
you're all good.
Thank you! Time to do some learning on these map things. :study:
I just got done with a course in C++ but it was a beginner course so they didn't cover some of this stuff. I'm sure once I read up on it and with some practice, I'll get it working.
Thanks for the starting point. :)
|All times are GMT -5. The time now is 01:47 PM.|