|
From: <hm...@gm...> - 2005-02-23 08:14:24
|
> hm...@gm... wrote: > > How does one deliver the size or length of an array in c++ (just as > > we have in java)? > > Others posted the "sizeof" trick, so I will add my two cents. > > Since you are using C++ and want Java-like behavior, you could use a > vector. Unlike its Java counterpart it offers overloaded operator[], > allowing array-style element access. It has a "size()" method similar to > the "length" property of a Java array. If you use the "at()" method you > get bounds checking. Finally, it is a template class. It gives you > strong type checking without any overhead of constantly making typecasts. > > Basically you can use a C++ vector just like an array, but it adds extra > features such as iterators, allocators, and metadata (e.g. length). If > you pass this vector to a function in another compilation unit you don't > need to pass the length, the vector stores that for you. > > -- > John Gaughan > http://www.johngaughan.net/ > jo...@jo... Oh, great! Thanks to you all!!!! Regards, Harp -- Lassen Sie Ihren Gedanken freien Lauf... z.B. per FreeSMS GMX bietet bis zu 100 FreeSMS/Monat: http://www.gmx.net/de/go/mail |