If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
LwSiX
Posts: 22 Joined: Wed Jan 17, 2007 2:24 pm
Post
by LwSiX » Fri Feb 09, 2007 3:42 am
Hi there,
Is it possible to use a char * as an index for an array? For example:
I used to do this with PHP, but c++ just isn't having this!
vitek
Bug Slayer
Posts: 3919 Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR
Post
by vitek » Fri Feb 09, 2007 5:45 am
No. Regular arrays are only indexable with integral values. If you want to index by something else, use a map [std::map, or the new core::map].
Travis
AaronA
Posts: 55 Joined: Tue Sep 12, 2006 1:31 am
Post
by AaronA » Fri Feb 09, 2007 6:50 am
Code: Select all
#define TEST_INDEX 0
#define BLAH_INDEX 1
#define somethingElse 2
#define Text 3
int numIndex[Text] = 43;
Its kinda lame, and probably not recommended, but it works.
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Fri Feb 09, 2007 9:17 am
Don't use defines, and even more important: Don't use lower case characters in defined strings. Guess what happens with your code if you later write 'char* Text = "x"'
LwSiX
Posts: 22 Joined: Wed Jan 17, 2007 2:24 pm
Post
by LwSiX » Fri Feb 09, 2007 1:16 pm
vitek wrote: No. Regular arrays are only indexable with integral values. If you want to index by something else, use a map [std::map, or the new core::map].
Travis
Thanks, thats exactly what I'm looking for.