Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 16th, 2005, 7:37 AM   #1
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Red face Array for all types

Is there a way to have an array contain a mixture of integers, floates, strings, characters? Just like a Python list.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 16th, 2005, 9:01 AM   #2
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4 Benoit is on a distinguished road
Null pointer?
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Mar 16th, 2005, 9:07 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
look up polymorphism, or polomorphic array i cant remember how to do it but thats what its called/
Berto is offline   Reply With Quote
Old Mar 16th, 2005, 12:42 PM   #4
brkstf
Programmer
 
brkstf's Avatar
 
Join Date: Feb 2005
Posts: 89
Rep Power: 4 brkstf is on a distinguished road
make a generic object that contains several data types. overload the constructor and accessors. then use malloc() with new to create an array of pointers to your objects.

this will waste a lot of space, though. as every object will have one of everything.
brkstf is offline   Reply With Quote
Old Mar 18th, 2005, 9:44 AM   #5
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Quote:
Originally Posted by Berto
look up polymorphism, or polomorphic array i cant remember how to do it but thats what its called/
A little over my head, but I will try! Thanks!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 18th, 2005, 1:32 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
standard template library... check it out.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Mar 19th, 2005, 5:29 PM   #7
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

Quote:
Originally Posted by Infinite Recursion
standard template library... check it out.
Found vectors and lists, but nothing for mixed types. I guess I could change everything to a string, or a vector of unions.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Mar 19th, 2005, 5:51 PM   #8
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Yup, there is... it's called a character array...

atof() converts char * to float.
atoi() converts char * to int.

and as for strings, that's what a char pointer is basically...
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:50 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC