parent class get the subclass object

Mike Parker via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 16 11:31:50 PST 2017


On Monday, 16 January 2017 at 16:31:41 UTC, Brian wrote:

> No, you don't understand I want to express meaning.
>
> other programing language is allow this.
>
> Your code more like the old C++.
>
> If a high-level programing language or need haevy like C++ impl 
> code, It's very regret.
>
> Can like rust / swift / php / java / C# ?

Perhaps template this parameters [1]:

```
class Base {
     void hello(this C)() {
         (cast(C)this).world();
     }
}

class Sub:Base {
     void world() { writeln("Hello world"); }
}

void main() {
     auto sub = new Sub;
     sub.hello();
}
```

[1] http://dlang.org/spec/template.html#TemplateThisParameter



More information about the Digitalmars-d mailing list