I have a vector with predefined size 4. And now i would like to know how many objects are present in that vector?? When i am trying vector.size() in for loop its giving the error because of its predefined size. Any one can help... Thank you
Originally posted by rasagna: When i am trying vector.size() in for loop its giving the error because of its predefined size.
Well, next time it does that, have a look at the error message. The words in an error message are usually designed so that they describe the problem that is happening, and that is most likely the case with the error message you are getting there. If you don't understand the message, then post it here.
I would venture a guess that you are mistaking a Vector's size for it's capacity. I'm guessing you are creating it using new Vector(4) which returns a Vector with an initial capacity of 4. It's size is 0 until something is added. size() will tell you how many objects are present in the Vector and it has nothing to do with the initial capacity you set it to.
Edit: Oops I meant size() not getSize(). Fixed. [ May 23, 2006: Message edited by: Ken Blair ]