LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 02-27-2007, 01:31 AM   #1
RavenLX
Member
 
Registered: Oct 2004
Posts: 88

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
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

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


Cheers,
Tink
 
Old 02-27-2007, 11:10 AM   #3
RavenLX
Member
 
Registered: Oct 2004
Posts: 88

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.
 
  


Reply

Tags
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


All times are GMT -5. The time now is 09:29 AM.

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