I've seen people use size_t
whenever they mean an unsigned integer. For example:
class Company {
size_t num_employees_;
// ...
};
Is that good practice? One thing is you have to include <cstddef>
. Should it be unsigned int
instead? Or even just int
?
Just using int
sounds attractive to me since it avoids stupid bugs like these (because people do often use int
):
for(int i = num_employees_ - 1; i >= 0; --i) {
// do something with employee_[i]
}