This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  STL Container .size()
  Submitted by



The following code is potentially dangerous because size() returns an unsigned type:

std::vector<Object v;
for(int i = 0; i < v.size() - 1; i++) ; 





Try this:

std::vector<Object v;
for(int i = 0; i < int(v.size()) - 1; i++) ; 



Overflow shouldn't be a problem - unless your objects are very small, you're likely to run out of address space before you run out of int :)

Andrew,
a_j_harvey@hotmail.com


The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.