Struct inheritance

Derek Fawcus dfawcus+dlang at employees.org
Wed Dec 4 12:03:12 UTC 2024


On Wednesday, 4 December 2024 at 11:51:57 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 05/12/2024 12:38 AM, Derek Fawcus wrote:
>> For which I get:
>> 
>> ```
>> MethB(P) Direct Parent
>> MethC(P) Direct Parent
>> 
>> MethB(P) Inherit Parent
>
> Due to no vtables, you cannot override a parent method and have 
> it see the override.
>
> MethC(C) Inherit Parent
>
>> ```
>
> The last example, assignment, this requires vtables and casting 
> up.
>
> Which structs cannot do.

So are you saying all three would be like the 'Direct Parent' 
case?

Presumably by making the Assign case cheat (manually forcibly 
casting a pointer of the child to a pointer of the parent), it 
would also yield the same result.

i.e.:

```
MethB(P) Direct Parent
MethC(P) Direct Parent

MethB(P) Inherit Parent
MethC(P) Inherit Parent

MethB(P) Assign Parent
MethC(P) Assign Parent
```

Or for the child method override, would you simply yield a 
compile failure - as it can never work, and has no backward 
compatibility issue?


More information about the dip.ideas mailing list