Shadowing member in inheritance hierarchy - why

Brother Bill brotherbill at mail.com
Sat Aug 9 04:02:03 UTC 2025


On Saturday, 9 August 2025 at 01:33:03 UTC, user1234 wrote:
> On Friday, 8 August 2025 at 23:52:31 UTC, Brother Bill wrote:
>> D language supports shadowing members, where the shadowed 
>> member has same name and different type on same type.
>>
>> Why is this enabled, and when should one use this advanced 
>> technique?
>
> That's not considered as shadowing as you can distinguish the 
> two members using a qualified access chain.
>
> ```d
> class A {int m = 1;}
> class B.A {float m;}
>
> assert((new B).A.m == 1);
> ```

I understand that members of various levels can be distinguished.
What I don't understand is why one would use this technique.


More information about the Digitalmars-d-learn mailing list