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?
Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
6 days ago Shadowing member in inheritance hierarchy - why | ||||
---|---|---|---|---|
| ||||
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? |
6 days ago Re: Shadowing member in inheritance hierarchy - why | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brother Bill | 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 or same type. Why is this enabled, and when should one use this advanced technique? |
6 days ago Re: Shadowing member in inheritance hierarchy - why | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brother Bill | 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? Overload rules are probably more fundamental then your thinking. Theres a core idea that hidden under the name "overload set".
whats foo? unhelpfully its an "overload set"; I have not seen a good explanation for what it is. |
6 days ago Re: Shadowing member in inheritance hierarchy - why | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brother Bill | 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.
|
5 days ago Re: Shadowing member in inheritance hierarchy - why | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | 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.
I understand that members of various levels can be distinguished. |
5 days ago Re: Shadowing member in inheritance hierarchy - why | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brother Bill | On Saturday, 9 August 2025 at 04:02:03 UTC, Brother Bill wrote: >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.
I understand that members of various levels can be distinguished. As a regular user you probably don't need it. I use it for meta programming and some quirky C++ interop where things can't be directly translated, for example when mixing virtual and non-virtual functions in C++ base/children classes (can't overload by virtual in D). Basically same approach can be used for example to nativize API of C-style OOP like one used in GTK to make it feel more D. |
5 days ago Re: Shadowing member in inheritance hierarchy - why | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brother Bill | On Saturday, 9 August 2025 at 04:02:03 UTC, Brother Bill wrote: >I understand that members of various levels can be distinguished. I skipped that part of the question because I thought that the fact that it's not a shadowing case invalidates it. To be frank the only time I've ever used that was with OOP and when a derived class introduced a derived instance of another class type:
So that whenever you work with a TypeDeclared or one of his derived class, you known that Obviously in this case a system of overlapped field would have made more sense but that does not exist in D (never seen that elsewhere either btw). |