Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-27-2007, 01:31 AM   #1
Registered: Oct 2004
Posts: 98

Rep: Reputation: 15
Question 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?

Last edited by RavenLX; 02-27-2007 at 01:33 AM.
Old 02-27-2007, 02:59 AM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
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.

Old 02-27-2007, 11:10 AM   #3
Registered: Oct 2004
Posts: 98

Original Poster
Rep: Reputation: 15
Thank you! Time to do some learning on these map things.

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.


array, c++, key, object, type, value

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash arrays question introuble Programming 1 05-20-2006 03:07 AM
Question about outputing arrays with pointers, then just arrays... RHLinuxGUY Programming 1 04-12-2006 05:40 AM
Data Type Java Arrays InJesus Programming 3 01-07-2006 05:09 PM
arrays of elements with [gcc4]array type has incomplete element type lmmix Linux - Software 0 02-26-2005 08:07 AM
C Question: arrays and pointers tundra Programming 7 07-19-2002 03:38 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration