Boost logo

Boost :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-03-31 22:17:50


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

> And in my opinion an integer is not a container, so I see no reason to use
> templates.


In Christ,
Steven Watanabe

Boost list run by bdawes at, gregod at, cpdaniel at, john at