parent class get the subclass object

Brian via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 16 04:15:49 PST 2017


Dlang should support such coding. What should I do?

import std.stdio : writeln;

abstract class Base(T)
{
     this()
     {
         _this = this;
     }

     void hello()
     {
         _this.world();
     }

     private
     {
         T _this;
     }
}


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

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



More information about the Digitalmars-d mailing list