digitalmars.D - Alias this and inheritance
- Jacob Carlborg (20/20) Jun 05 2017 The following code does not compile:
 - ketmar (4/22) Jun 05 2017 yes, afaik. the reasons are similar to not automatically bringing overlo...
 
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?
-- 
/Jacob Carlborg
 Jun 05 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.
 Jun 05 2017








 
 
 
 ketmar <ketmar ketmar.no-ip.org>