Page 1 of 1
array of array in irrlicht
Posted: Wed Mar 15, 2006 9:25 pm
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???
Posted: Wed Mar 15, 2006 10:23 pm
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.
Posted: Thu Mar 16, 2006 12:58 pm
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]
Posted: Thu Mar 16, 2006 2:09 pm
by Heizi
this way it cannot work I think.
perhaps it works if you use () instead of [].
Posted: Thu Mar 16, 2006 5:35 pm
by vitek
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));
Posted: Fri Mar 17, 2006 8:46 pm
by warden@guest
thanx a lot vitek, i'll try that!