Struct inheritance
Derek Fawcus
dfawcus+dlang at employees.org
Tue Dec 3 21:37:35 UTC 2024
On Tuesday, 3 December 2024 at 20:45:32 UTC, Richard (Rikki)
Andrew Cattermole wrote:
>> Would your proposal allow:
>>
>> ```d
>> struct Grandad {
>> }
>>
>> struct Dad : Grandad {
>> }
>>
>> struct Child : Dad {
>> }
>> ```
>>
>> (I'm not sure if the scheme I mention does, I'd have to reread
>> the specs; but I believe it doesn't).
>
> Yes.
OK.
I'd suggest that the member variable version of 'alias this' is
also a form of embedding / composition.
It allows one to control the exact in-memory layout of the struct
so defined. Whereas AFAICT, the inheritance suggestion does not.
Issues/Questions with inheritance suggestion:
1. What is the in memory layout?
(Presumably the 'parent' elements simply appear first in
memory).
2. Inability to control in memory layout.
3. What type is passed to a parent struct member function when
called on the child.
(Presumably it is the class behaviour of passing the child
stuct, with 'isA' relations)
(If not, then there are two different behaviours for
inheritance - class vs struct)
4. What other parts of the class behaviour will apply?
(i.e. will the class implicit mutex lock now be instantiated)
(if not, then classes and structs using inheritance will have
different threading behaviour)
More information about the dip.ideas
mailing list