Can we just have struct inheritence already?

SonicFreak94 sonicfreak94 at hotmail.com
Tue Jun 11 01:23:29 UTC 2019


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.


More information about the Digitalmars-d mailing list