Something like ADL from C++?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Fri Dec 6 10:18:50 UTC 2024
On 06/12/2024 10:46 PM, Arafel wrote:
> On 6/12/24 9:05, Richard (Rikki) Andrew Cattermole wrote:
>> I'm fully aware of template this parameters, I was trying to get them
>> to work 10 years ago.
>>
>> They have problems that prevent their usage.
>>
>> 1. They are templates, so not in vtable
>> 2. They require the this pointer to be typed to the child (extremely
>> easy for this to not be the case, see 1)
>> 3. Because they are not virtual, you cannot up cast (see 2)
>> 4. Cannot be over ridden for any manual behavior
>>
>> All and all, they become very complex for common usage, quite fragile
>> if you don't use them right, not the kind of thing you recommend to
>> people who are use to runtime reflection.
>
> That's true, I found a workaround using constructors and registering
> classes there, but currently it only works with one level of inheritance
> (without user intervention, the whole purpose of it):
Yes, once you have a level in the hierarchy that adds a constructor, you
basically lose the ability to call that constructor with the template
this parameter.
Which means the user derived type has to be final.
A struct starts to look inviting with all these issues present in
classes lol
More information about the Digitalmars-d
mailing list