array of array in irrlicht

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
Lev_a
Posts: 52
Joined: Tue Jan 10, 2006 5:59 pm
Location: Toronto, Canada

array of array in irrlicht

Post by Lev_a »

How I can create array of array and than use it like MyArray[j].

Now I used:
irr::core::array<s32> node;
and than node = ....

irr::core::array<irr::core::array<s32>> node; - it's wrong;

Or I should use:
irr::core::array<s32 *> node???
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

The only thing that is wrong is the >>, which should be > >.
Though, frankly, as long as long as dimensions are known and don't change independently at runtime, I'd use a single flat array and do two-dimensional access via x+xsize*y as the index.
warden
Posts: 11
Joined: Thu Nov 24, 2005 3:54 pm

Post by warden »

i'd like to use this thread for another question on arrays:

is it possible to initialize an array with values from start?

i.e. core::array<int> array = [1,2,3,4] ?

until know i would rather use
core::array<int> array;
for (int i=0; i<4; i++) array.push_back(i+1);

but this doesn't help me when i have unordered items such as [4,2,1,3]
Heizi
Posts: 30
Joined: Mon Oct 10, 2005 11:23 am
Location: Steinach/Baden

Post by Heizi »

this way it cannot work I think.
perhaps it works if you use () instead of [].
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

s32 arr[] = { 4, 2, 1, 3 };
I think that is what you want. This is called aggregate initialization and only works with aggregate types [structure, union, or array or plain old data]. The core::array template does not meet these requirements.

Of course you could always do this...

Code: Select all

#define countof(x) (sizeof(x) / sizeof(*x))
s32 arr[] = { 4, 2, 1, 3 };

core::array<s32> vals;
for (u32 i = 0; i < countof(arr); ++i)
 vals.push_back(arr[i]);

// if you used the c++stdlib
std::vector<s32> vec;
std::copy(arr, arr + countof(arr), std::back_inserter(vec));
warden@guest

Post by warden@guest »

thanx a lot vitek, i'll try that! :D
Post Reply