ssercpp12 / Homework

Homework result for 12 sser cpp
1 stars 8 forks source link

How should I deal with a negative 'index'? #15

Open oath-jia opened 11 years ago

oath-jia commented 11 years ago

For example, in bool Set(size_t index, Value* in_value), index is a size_t number. So though we execute list.Set(-1, in_value), the computer think that -1 is not -1 but 4294967295. If we judge if (index >= 0), it's always right. How should I deal with this.

ssercpp12 commented 11 years ago

You can do some Type Casting and check. However, there is something wrong with the comment. And this also can be the wrong of the user, the interface is size_t, why you pass a negative value?

oath-jia commented 11 years ago

Just because of the comment in value.h

// Return true if successful, or false if the index is negative or
// the value is a null pointer
bool Set(size_t index, Value* in_value)