Shadowing member in inheritance hierarchy - why

monkyyy crazymonkyyy at gmail.com
Sat Aug 9 00:59:21 UTC 2025


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".

```d
import std;
void bar(int){"int".writeln;}
void bar(float){"float".writeln;}
ref bar(bool b){
   bool bar;
}
alias foo=bar;

void foobar(alias A)(){
   A(1);
   A(13.37);
   A=true;
}
unittest{
   foobar!foo;
}
```

whats foo? unhelpfully its an "overload set"; I have not seen a 
good explanation for what it is.


More information about the Digitalmars-d-learn mailing list