From: John Maddock (john_at_[hidden])
Date: 2008-04-01 04:49:56
Steven Watanabe wrote:
> Maarten Kronenburg wrote:
>> In my opinion an unsigned integer is a, works like a and can be
>> substituted as an integer, and so is a modular integer, and as far
>> as I'm concerned also an allocated integer. This is why I choose for
>> derivation, and then with the base pointer to derived object (as
>> quoted above) to runtime polymorphism.
> I strongly disagree.
> 1) An unsigned integer only works like an integer for non-mutating
> operations. If clients take parameters of const integer&, sure,
> will work fine in this context. Treating non-const integers
> polymorphically is a very bad
> idea, though. Code that does so has to be very carefully designed to
> make sure that
> it can handle all the combinations. If you have to use inheritance,
> make both integer and
> unsigned_integer inherit from a common base.
> 2) I would expect an integer class to be a value object. virtual
> functions don't play
> well with value objects, because to prevent slicing, everything has to
> be held by
> 3) unsigned_integer + unsigned_integer should return an
> unsigned_integer. There
> is no way for the result to be negative. This is even more glaring
> for modular_integer
+1 agreement from me too.
>> And in my opinion an integer is not a container, so I see no reason
>> to use templates.
That's irrelevant IMO. For that matter, a value class doesn't have to be a
template either - except possibly for the allocator parameter if required.
And come to that, if the object performs allocation it is a container
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk