Dynamic templated virtuals - I still often want them

bauss jj_1337 at live.dk
Mon Mar 14 07:48:49 UTC 2022


On Saturday, 12 March 2022 at 05:10:10 UTC, surlymoor wrote:
> On Thursday, 23 July 2020 at 02:38:27 UTC, Adam D. Ruppe wrote:
>> ...

While not exactly the same, this can be worked around by using 
the constructor of the base class.

```d
class Base {
     private string _stringof;
     this(this This)() { _stringof = This.stringof; }

     string serialize() {
         return _stringof;
     }
  }

  class Derived : Base {

  }

  void main() {
     Base b = new Derived();
     assert(b.serialize() == "Derived"); // Passes
  }
```



More information about the Digitalmars-d mailing list