Shadowing of members

comco void.unsigned at gmail.com
Wed Jan 9 13:59:21 PST 2013


On Wednesday, 9 January 2013 at 21:30:32 UTC, H. S. Teoh wrote:
> Because I forgot to declare 'a', I end up overwriting a base 
> class
> member which I didn't intend to change. Not good. (Furthermore, 
> if the
> class hierarchy is big, I may not find out about this until 
> much later
> -- I may not even be aware that some superclass declares 'a'.)
>
>
> T

At least this will be consistent behaviour. If it is an error, 
then a perfectly fine code now will stop compiling after someone 
(evil person!) adds a protected member 'i' to one of the 
super-super-super classes. Now not only my loop will stop to 
compile, but the inheritance will have the nice side effect of 
not allowing to use i for iteration in __any__ method.
Of course, this is an extreme example, but valid.


More information about the Digitalmars-d mailing list