(Michael Chinen)

Day: February 1, 2012

std::vector size() method and gotcha with unsigned vs signed

Guess who wins in signed vs unsigned integer conversion? I guessed wrong today, or rather, I’ve been assuming wrong for quite a while. consider this example: std::vector<SomeClass*> myVec; int countdown = -1; // … (fill the vector) if (countdown < myVec.size()) countdown++; // this will never get hit myVec.size() returns size_t, which is an unsigned […]

Back to top