Can we just have struct inheritence already?

Exil Exil at gmall.com
Tue Jun 11 01:33:58 UTC 2019


On Tuesday, 11 June 2019 at 01:23:29 UTC, SonicFreak94 wrote:
> On Sunday, 9 June 2019 at 13:59:25 UTC, Jonathan M Davis wrote:
>> However, if you're using this pattern frequently, what's 
>> stopping you from just creating a function or template to use 
>> with mixin that takes care of it for you? I would have thought 
>> that it would be fairly straightforward to do something like
>>
>> struct DerivedStruct
>> {
>>     mixin(aliasAsMember!BaseStruct);
>> }
>>
>> and then it really isn't any more complex than
>>
>> struct DerivedStruct : BaseStruct
>> {
>> }
>>
>> would be.
>>
>> - Jonathan M Davis
>
> Yes it is!
>
> I do reverse engineering followed by code injection, etc etc. 
> When there are POD types that share a common set of members, 
> simple inheritance saves a whole lot of time.
>
> As an example of usefulness: when some code in the binary 
> you're injected to expects x field to be at y offset, and 
> another function expects that same field to be at the same 
> offset, with the addition of some extra data that the previous 
> function is unaware of, the simple solution is obvious: inherit 
> a base structure that contains the common members.
>
> It also reduces the need for workarounds when using types and 
> non-assembly callable function declarations.
>
> Because D does not afford that luxury, I frequently have to 
> choose a language like C++ for the sake of *maintenance* 
> (hah!), and that sucks.

You can do this with structs and alias this now. I also doubt 
code injection is something a language should consider for its 
use cases. It is only really useful for a niche.



More information about the Digitalmars-d mailing list