[SOLVED] Irrlicht array of strings problems

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.
Post Reply
madoc
Posts: 32
Joined: Fri Feb 11, 2005 10:43 am

[SOLVED] Irrlicht array of strings problems

Post by madoc »

list is a linked list internal to the class that returns getName as const wchar_t * I know you cant just in a linked list, this is just an example, the name returns fine.

Code: Select all

array<stringw> *someclass::thefunc() {
 array<stringw> *ret = new array<stringw>;
 u32 i; // I was using u16 but noticed that the [] operator wanted u32
 i = 2;
 while(i--) {
  ret.push_front(list[i]->getName());
 }
 return ret;
}
I switched from push_back to push_front because with the debugger i noticed that allocated went to 3 if I used pushed back, even with only 2 elements.
then to access it:

Code: Select all


u32 i;
stringw node;
nodes = thefunc();
i = nodes->size();
while(i--) {
 node = nodes[i]; // This is the line 30 compiler is talking about below 
}
delete nodes;
Now thats what I want, but it dosnt work if theres more then one element the first element works fine but if its 2 the second element dosnt work (because I use while i-- this means it crashes first time through the loop)
so I tried changing the whole thing to use arrays of wchar_t, yea it didnt like that. So I tried const wchar_t *, so its an array of pointers to const whcar_t's, which compiles fine, seems to run fine (although isnt it odd I can only ever see the 1 element in the debugger even if its supposed to be 2, when the second one is assigned 'data' goes to the second value.
BUT when I try to access it
1>y:\development\launcher\launcher\cmain.cpp(30) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'irr::core::array<T>' (or there is no acceptable conversion)
Hrm so I figured I'd try casting it,
1>y:\development\launcher\launcher\cmain.cpp(30) : error C2440: 'type cast' : cannot convert from 'irr::core::array<T>' to 'const wchar_t *'
This is about where the obsceneties came in.
Searched around the forums and found 1 other guy with a similar problem where assigning with push_back to an array seemed to overwrite the first element and not create a second. But he rewrote all his code so he didnt have to use the array :)
I don't have that option unfortunatly.

All I want, is a function that creates an array of strings, or wchar_t or whatever, an array of different strings of text and returns them in some accessible manner. The problem is its an unknown size so rather then loop through them to count them then to parse them I figured I'd try Irrlicht Arrays.

But their driving me nucking futs!
Any help would be appriciated!

I've actually spent like 3hrs arguing with the compiler and the debugger and cannot get it to work, I've tried many many many things I just included my latest forey into it.
Last edited by madoc on Tue May 12, 2009 5:38 pm, edited 1 time in total.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

I think the problem is that the functions returns a pointer to an array.
So the compiler interprets the [] as an access to an array of arrays.

Try to dereference to pointer

Code: Select all

node = (*nodes)[i];
(didn't test it)

And what's so bad that the array allocates extra memory ?
Take a look at the source of array and you see that there are variables for allocated and used. Used is what you have to worry about.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
madoc
Posts: 32
Joined: Fri Feb 11, 2005 10:43 am

Post by madoc »

That worked perfectly! Thank you! Was driving me insane!
Post Reply