
1 Jun
2006
1 Jun
'06
10:06 p.m.
Marsh J. Ray wrote:
Seems to me that, if the author is really set on using inheritance here, integer should inherit from unsigned_integer, since integer can do everything that an unsigned can do, but not vice-versa. Integer extends unsigned with the ability to represent negative values and the result of subtraction.
No, that's not true. (See Scott Meyers, Effective C++, Item 35) If a signed integer IS-A unsigned integer, then all invariants of unsigned integer must hold true for signed integer - including the one about negative values. ("There's no such thing.") Sebastian Redl