Ian Collins wrote:
> Dmytro wrote:
>> Hi!
>>
>> This code is ok:
>>
>> template<class T>
>> struct Container
>> {
>> T x;
>> typedef int size_type;
>> size_type size() { return sizeof T; }
>> };
>>
>> Why the compiler (VC7) does not compile the following code?
>>
>> template<class T>
>> struct Container
>> {
>> T x;
>> typedef int size_type;
>
> Why use int for a size_type? Does a negative size make sense?
Actually, it does. If you want to be able to get an offset between two
arbitrary elements, that offset must be a signed type and will only be able
to span half of the range of the unsigned size type. So the size couldn't
be more anyway. And then, it's always a bad idea to mix signed and
unsigned, so actually, I would prefer a signed size type.
|