STL vector objects have their own default capacity, which is implementation dependent. You should be able to determine this value rather simply. Something like this should do.
vector<int> v;
cout << "default capacity of vectors in my STL implementation is " << v.capacity <<
Of course you can specify a capacity, if you desire.
vector<int> v(5);
cout << "the capacity of v is " << v.capacity();
cout << "the size of v is ";
if(v.empty())
cout << "zero" << endl;
else
cout << v.size();
You can also specify default values.
vector<int> v(5,0);
for(int i = 0; i < 5; ++i)
cout << "v[" << i << "] = " << v[i] << ' ' ;
Data structures can be very big, meaning passing them back and forth by value can be costly. It's often wiser to pass them by reference, making them const references if you don't want the function to change any of the values in the structure being passed. So I'd declare the structure using my own defualt capacity and default all values to the desired default value and then pass that structure to a function by reference in it's current state.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Offline 2,253 posts
since Jul 2005