Saturday, May 22, 2010

So how do I array.length like on java but with c++?

int klip_animation[3][4][2][12] = {


{


{{0, 5, 5, 5, 10, 10, 0, 0, 10, 10, 0, 0},{0, 10, 11, 27, 21, 27, 21, 27, 37, 47, 37, 47}},


{{0, 5, 5, 5, 10, 10, 0, 0, 10, 10, 0, -7},{0, 10, 11, 27, 21, 27, 21, 27, 37, 47, 37, 44}},


{{0, 5, 5, 5, 10, 10, 0, 0, 10, 10, 0, -13},{0, 10, 11, 27, 21, 27, 21, 27, 37, 47, 37, 37}},


{{0, 5, 5, 5, 10, 10, 0, 0, 10, 10, 0, -7},{0, 10, 11, 27, 21, 27, 21, 27, 37, 47, 37, 44}}


},


{


{{-5, 0, 0, 0, 5, 5, 5, 5},{-47, -37, -36, -20, -26, -16, -10, 0}},


{{0, 5, 5, 5, 10, 10, 10, 10},{0, 10, 11, 27, 21, 31, 37, 47}},


{{0, 5, 5, 5, 10, 10, 10, 10},{0, 10, 11, 27, 21, 31, 37, 47}}


},


{


{{0, 5, 5, 5, 10, 10, 10, 10},{0, 10, 11, 27, 21, 31, 37, 47}},


{{0, 5, 5, 5, 10, 10, 10, 10},{0, 10, 11, 27, 21, 31, 37, 47}},


{{0, 5, 5, 5, 10, 10, 10, 10},{0, 10, 11, 27, 21, 31, 37, 47}}


}};





when i use size of i get this instead





sizeof(klip_animation[0][0][0][0])= 4


...


sizeof(klip_animation[0]) = 1152

So how do I array.length like on java but with c++?
in c++, if you want to use an array, it's advised to know the size of it first.





If you do anything else where the size can vary, use a vector/list/deque/map/set etc... from the stl library.





I believe sizeof returns the size of the data type ( being integer in this case? ) which is why it would return 4 ( 32bit integer )


No comments:

Post a Comment