Error with irr::core::array when it's in the heap.

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
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Error with irr::core::array when it's in the heap.

Post by cederron »

Hello all,
I need to create an array in the heap and i use this code

Code: Select all

irr::core::array<rect<s32>> *IrrArray = new irr::core::array<rect<s32>>();
rect<s32> r= &IrrArray[0];
With this code I get the error:
error C2440: 'initializing' : cannot convert from 'irr::core::array<T> *' to 'irr::core::rect<T> '

However the same thing but in the stack works fine:

Code: Select all

array<rect<s32>> IrrArray;
rect<s32> r = IrrArray[0];
I thought it would work with the array in the heap, but it's not, maybe I'm not allocating the array correctly but I can't figure out whats going on.

Edit: well, I see it's trying to convert the array instead of the element in the array, but I don't know why :?:
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Two things...

First, the blocks of code you posted are not equivalent. It looks like you are confusing the address-of operator [&] with the dereferencing-star operator [*]. Your error is that you are taking the address of an array pointer and then indexing [which gets you an array pointer]. You would need to write (*IrrArray)[0] to get what you want.

Second, are you absolutely sure that you want to create a pointer to an array?
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Post by cederron »

thank you vitek. I need to revise my c++ skills.
I need to use a pointer to an array because im using it inside a c++/cli class and i can only use a pointer there.

Thank you again.
Post Reply