In the C++ Primer
book, Chapter (3), there is the following for-loop that resets the elements in the vector to zero.
for (vector<int>::size_type ix = 0; ix ! = ivec.size(); ++ix)
ivec[ix] = 0;
Why is it using vector<int>::size_type ix = 0
? Cannot we say int ix = 0
? What is the benefit of using the first form on the the second?
Thanks.
Best Answer
The C++ Standard says,
Then it adds,
So most likely,
size_type
is a typedef ofsize_t
.And the Standard really defines it as,
So the most important points to be noted are :
size_type
isunsigned
integral, whileint
is not necessarilyunsigned
. :-)