subclassing

Steven Schveighoffer schveiguy at yahoo.com
Tue Nov 2 13:59:12 PDT 2010


On Tue, 02 Nov 2010 16:35:39 -0400, spir <denis.spir at gmail.com> wrote:

> On Tue, 02 Nov 2010 12:33:16 -0400
> Jesse Phillips <jessekphillips+D at gmail.com> wrote:
>
>> spir Wrote:
>>
>>
>> > * Why does D allow me redefining (data) slots in the subclass  
>> OddSquares, which exist in the superclass? (I did this first without  
>> noting, by copy & paste ;-)
>>
>> This is either a bug or so that you don't have name clashes with all  
>> the super classes (could really reduce the available names).
>
> I have name clashes, that's what I meant with "redefining". Test case:
>
> class SC {int i;}
> class C : SC {int i;}
>
> compiles. If this (non-)behaviour of the compiler is not intended for a  
> good reason, then it may be considered a bug. At least, we should get a  
> warning, don't you think? Also, this is anyway bad design and goes  
> against the fact that in D (and OO in general), class features are  
> precisely identified by name... See also, bug below.

The behavior is intentional.  It's similar to C++ behavior.  Usually, you  
only do it with private members which are not accessible to the derived  
class.

-Steve


More information about the Digitalmars-d-learn mailing list