Page 1 of 1
4 Replies - 875 Views - Last Post: 19 July 2007 - 11:19 AM
Replies To: structures
Posted 18 July 2007 - 12:06 PM
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.
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).
Page 1 of 1