Hiding class pointers -- was it a good idea?
James Dennett
jdennett at acm.org
Thu Aug 16 22:41:57 PDT 2007
Walter Bright wrote:
> James Dennett wrote:
>> Walter Bright wrote:
>>> That's known as the 'slicing' problem. It's pernicious in that it can be
>>> extremely hard to expose via testing or code reviews, yet will expose
>>> the program to unpredictable behavior.
>>
>> It's trivially detected by various automated tools, which
>> can flag any non-abstract base class. (Such classes almost
>> invariably indicate bad design in any case.) Clearly it
>> would be simple for a compiler to detect when a concrete
>> class was used as a base class. There's no need to remove
>> value semantics in order to solve this problem; it's
>> something of a sledgehammer solution.
>
> That's true if you agree with the notion that only abstract classes
> should be used as base classes, which I do not agree with.
Then you lose benefits of static type checking for operations
such as equality comparisons, unless you have ugly special
cases. How does D handle this? Guess I'll go look it up.
-- James
More information about the Digitalmars-d
mailing list