Dynamic templated virtuals - I still often want them

surlymoor surlymoor at cock.li
Sun Mar 13 06:49:30 UTC 2022


On Saturday, 12 March 2022 at 13:00:24 UTC, Timon Gehr wrote:
> The way I work around this is by putting template mixins into 
> all subclasses, using `typeof(this)`. (It's a bit finicky 
> though, template mixins are notorious for exposing forward 
> reference compiler bugs.)

Yeah, I ended up doing this since I made the opening post. 
Luckily I've yet to experience any compiler bugs, so yourself and 
others must have ironed most of them out by now, lol. But to have 
what Adam proposed would still be amazing.

On Saturday, 12 March 2022 at 15:06:58 UTC, zjh wrote:
> Each class should have a `This` type or information like rust's 
> `self/Self` to indicate `Self Type`.
> `The base class` should have a special `This` template 
> parameter. As long as subclass inherits it, `the subclass` will 
> automatically replace `This` as itself Type.
> In fact, it once again shows the `benefits` of `inheritance`.
> `Struct` should be able to inherit, or even multi inheritation 
> like `C++`.

Mostly in agreement, but I don't really see the need for structs 
to have vtables and whatnot if you are given the ability to 
easily allocate class instances however you please.


More information about the Digitalmars-d mailing list