//the class
class Vertex {
public:
float x,y,z;
};
//then using it in an array
Vertex myVertices[10];
//i want a .size() function to tell me the array is 10
//eg.
int theSize = myVertices.size() //theSize is 10
how could i do this?
Thanks,
I want to make size() function like in the vector class
You know with vectors how it has the .size() function to tell you the size of the array. Well ive got my own class
What you have is an array. Arrays don''t have a size() in C (they do in Java, it''s nice). If you want something with a size, you pretty much have to write your own Vector.
ah i see, that sucks
i love all javas little features, but i so hate their really long method/function names. I can never remember them.
i love all javas little features, but i so hate their really long method/function names. I can never remember them.
If you''re using fixed sized arrays (ala built in arrays) and really want a size function then use boosts array class.
Also, you get the added goodness of begin/end functions so you can easily use STL algorithms on it aswell. Plus more gooderness
Also, you get the added goodness of begin/end functions so you can easily use STL algorithms on it aswell. Plus more gooderness
quote:Original post by pinacolada
What you have is an array. Arrays don''t have a size() in C (they do in Java, it''s nice). If you want something with a size, you pretty much have to write your own Vector.
Ahem, Java''s arrays don''t have a size(), they have a length.
Notice, it''s written like it''s a field, but it''s apparently supposed to be an operator. When you apply the reflection interface to an array, Java will recognize it as a class in some ways but not in others - and there will be no ''length'' among the fields. The metamodel is all screwed up :/
Interesting reading: http://c2.com/cgi/wiki?JavaArraysShouldBeFirstClassObjects
Also, if you''re sure that what you have is an actual array (not a pointer to the first element, or a pointer to a dynamically allocated array), you can get the size of the array:
#define array_size( x ) \
( sizeof( x ) / sizeof( (x)[0] ) )
-Brian
#define array_size( x ) \
( sizeof( x ) / sizeof( (x)[0] ) )
-Brian
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement