Alias this and inheritance
    ketmar via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Mon Jun  5 06:19:55 PDT 2017
    
    
  
Jacob Carlborg wrote:
> The following code does not compile:
>
> void foo(string a) {}
>
> class Base
> {
>      alias bar this;
>
>      string bar()
>      {
>          return "";
>      }
> }
>
> class Sub : Base {}
>
> void main()
> {
>      auto sub = new Sub;
>      foo(sub);
> }
>
> But if the "alias this" is copied/moved to the subclass it works. Is this 
> expected behavior?
yes, afaik. the reasons are similar to not automatically bringing overloads 
when you're doing override, and avoiding other "automatic helpers" most of 
the time: it can quickly get out of control.
    
    
More information about the Digitalmars-d
mailing list