4 Replies - 821 Views - Last Post: 19 July 2007 - 11:19 AM Rate Topic: -----

#1 gogole  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 131
  • Joined: 17-July 07

structures

Posted 18 July 2007 - 11:48 AM

could i label structures in c++ as actually being multi-dimensional arrays which can store different data types?
Is This A Good Question/Topic? 0
  • +

Replies To: structures

#2 rockstar_  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 33
  • View blog
  • Posts: 189
  • Joined: 16-October 06

Re: structures

Posted 18 July 2007 - 12:06 PM

View Postgogole, on 18 Jul, 2007 - 11:48 AM, said:

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_
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5389
  • View blog
  • Posts: 27,386
  • Joined: 10-May 07

Re: structures

Posted 18 July 2007 - 12:14 PM

Are you asking like this?
   struct {
		char item[MAX];
		float cost;
		int amount;
	} x[MAX];


If so, take a look here.
Was This Post Helpful? 0
  • +
  • -

#4 gogole  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 131
  • Joined: 17-July 07

Re: structures

Posted 19 July 2007 - 11:12 AM

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).
Was This Post Helpful? 0
  • +
  • -

#5 gogole  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 131
  • Joined: 17-July 07

Re: structures

Posted 19 July 2007 - 11:19 AM

no2pecil please explain your code .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1