Why can't we derive struct's?

12345swordy alexanderheistermann at gmail.com
Mon Dec 24 23:06:26 UTC 2018


On Monday, 24 December 2018 at 19:57:50 UTC, Walter Bright wrote:
> On 12/24/2018 10:10 AM, H. S. Teoh wrote:
>> If you can convince him, that would be great!
>
> You'd need very compelling use cases.
>
> It's like adding more and more horsepower to a car. At some 
> point, it doesn't make the car better.
>
> Or like operator overloading. C++ has much more expansive rules 
> for operator overloading. They lead to clever programs, and 
> some people swear by them, but are they *better* programs? For 
> example,
>
> * iostreams
>
> * regex DSL 
> https://pdfs.semanticscholar.org/e630/5f84bca36251fd5a4ffa5f00e0effc8aaa7d.pdf
>
> ? I don't buy it. I've never seen an elegant use of the more 
> expansive power (even though many insist those two examples are 
> elegant).

A use case that pops in my head is to avoiding using inheritance 
as that is not always ideal tool, when it comes to structs/class 
as you have no control on how it does implicit conversions.
No Basic Event programming.
No Design by Introspection.
No Data Conversion in Regards to Passing Member Variables.
You class/struct may end up with functions/variables that you 
don't want, which creates needless bloat.
If you want to support multiple implicit conversion with the 
current features, then you need multiple alias this, which is not 
a good solution as
A.) It is multiple inheritance. Which we both agree it is a 
terrible idea.
B.) Multi alias this still hasn't been implemented already. 
*Throws table*



More information about the Digitalmars-d mailing list