The problem is that there is a potential (discontinuous) problem that can be incurred when working with unsigned comparisons. If you are on a 32-bit machine where the signed int is 4 bytes, it is possible that the size of the vector may exceed the maximum amount represented by this type. When this happens, you will receive a signed overflow and therefore Undefined Behavior.
Here are some alternatives you can use:
for (std::vector<classname>::size_type i = 0; i < object.size(); ++i);
This is guaranteed to be correct, since it returns a type of size .
iterators
std::vector<classname>::iterator it; for (it = object.begin(); it != object.end(); ++it);
for (auto& a : object) {
for (std::size_t i = 0; i < object.size(); ++i);
As doomster said in the comments, std::size_t will most likely be the bit size of your base platform.
unsigned int :
for (unsigned int i = 0; i < object.size(); ++i);
Note. Using this, you assume that size returns a 32-bit integer. This is usually not a problem, but you cannot be too sure; use any of the above methods if you can.
Another unique_ptr advice regarding your code is to use the unique_ptr / shared_ptr vector to facilitate memory management:
std::vector<std::unique_ptr<classname>> object;
source share