Can we just have struct inheritence already?

Exil Exil at gmall.com
Sun Jun 9 15:36:56 UTC 2019


On Sunday, 9 June 2019 at 15:02:29 UTC, KnightMare wrote:
> On Sunday, 9 June 2019 at 13:59:25 UTC, Jonathan M Davis wrote:
>> I've never even seen code use such a pattern before, and 
>> honestly, it seems really weird to me to even write code that 
>> acts like one struct is derived from another, because without 
>> polymorphism, I wouldn't really have thought that that would 
>> make any sense.
>>
>> struct DerivedStruct
>> {
>>     mixin(aliasAsMember!BaseStruct);
>> }
>>
> such construct says "like-a" for me.
> its some difficult workaround of
>> struct DerivedStruct : BaseStruct
>> {
>> }
>>
> clear and explicitly says "is-a" for me
>
> Point3D is a Point2D plus z, not Point3D like a Point2D with z. 
> maybe for u this is same mean.
>
> The point(another mean) lays in human habits, all of us know 
> C++, we expecting clear and obvious things. The point is not 
> that which is more correct, but that it is more familiar, what 
> is expected.
> Same for double.init=NaN - maybe its right in some view, but 
> all langs that I know initialize globals with zeroes. I 
> expecting zeroes. I expecting "using noninitalized variable" 
> when I do something d+=.. with such var not the NaN.
> When u have a deal with known things u do less errors and typos 
> than when u fight with unexpected "right way".

Don't think I've seen a Point3D ever use inheritance to with a 
Point3D. Basically all the functions will need to be 
reimplemented. And some don't even make sense to reimplement 
because they only apply to 2d.

You can also make a 2D point from each axis, xy, xz, yz, and you 
can switch those around etc.


More information about the Digitalmars-d mailing list