Dynamic templated virtuals - I still often want them

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


On Monday, 14 March 2022 at 07:59:00 UTC, zjh wrote:
> On Monday, 14 March 2022 at 07:48:49 UTC, bauss wrote:
>> 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:
>>>> ...
>>
>
> but this fails:
> ```d
> class Base {
>     string serialize(this This)() {
>         string _stringof = This.stringof;
>         return _stringof;
>     }
>  }
>  class Derived : Base {
>  }
>
>  void main() {
>     Base b = new Derived();
>     assert(b.serialize() == "Derived");
> }
> ```

Yes, that's the point of my message, that it's not the same but 
it can be used to workaround, so you basically "cache" the values 
to use in the constructor, since you can't retrieve them 
elsewhere.

The code I shared will achieve the same in theory, while of 
course not being 1:1


More information about the Digitalmars-d mailing list