Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,673 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,175 people online right now. Registration is fast and FREE... Join Now!




structures

 
Reply to this topicStart new topic

structures

gogole
post 18 Jul, 2007 - 10:48 AM
Post #1


D.I.C Head

Group Icon
Joined: 17 Jul, 2007
Posts: 131



Dream Kudos: 25
My Contributions


could i label structures in c++ as actually being multi-dimensional arrays which can store different data types?
User is offlineProfile CardPM

Go to the top of the page

rockstar_
post 18 Jul, 2007 - 11:06 AM
Post #2


D.I.C Head

Group Icon
Joined: 16 Oct, 2006
Posts: 187



Dream Kudos: 275
My Contributions


QUOTE(gogole @ 18 Jul, 2007 - 11:48 AM) *

could i label structures in c++ as actually being multi-dimensional arrays which can store different data types?

I guess I'm not really completely understanding your question, whether it's academic or if you're actually trying to implement this. When I want to use a generic data structure to house different data types, I usually only have a void * pointer, that points to the actual type that I want to use. The problem with this is that you're going to need to add extra attributes to the structure which will help to identify the type, like a char * or something. For instance, you create a map of four ints and a string. You need to add some sort of identifier so that as you iterate through the linked list, you don't try to raise the string to a power of 2 or whatever you're trying to do.

Not a clean solution, but a solution all the same. I can't think of any other way to create a "multi-dimensional array" that is generic enough to contain any data type you give it.

rockstar_
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 18 Jul, 2007 - 11:14 AM
Post #3


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


Are you asking like this?
CODE

   struct {
        char item[MAX];
        float cost;
        int amount;
    } x[MAX];

If so, take a look here.
User is offlineProfile CardPM

Go to the top of the page

gogole
post 19 Jul, 2007 - 10:12 AM
Post #4


D.I.C Head

Group Icon
Joined: 17 Jul, 2007
Posts: 131



Dream Kudos: 25
My Contributions


since in c++ multi-dimensional arrays can't be called by: arrayname([],[]);(not quite sure) i was thinking of using a structure to house arrays for the same thing arrayname([],[]); does.i need this to organise passwords and usernames (definately strings).
User is offlineProfile CardPM

Go to the top of the page

gogole
post 19 Jul, 2007 - 10:19 AM
Post #5


D.I.C Head

Group Icon
Joined: 17 Jul, 2007
Posts: 131



Dream Kudos: 25
My Contributions


no2pecil please explain your code .
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 06:16AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month