Can we just have struct inheritence already?

Manu turkeyman at gmail.com
Sun Jun 9 22:05:48 UTC 2019


On Sun, Jun 9, 2019 at 2:50 PM Ola Fosheim Grøstad via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Sunday, 9 June 2019 at 21:35:19 UTC, Ola Fosheim Grøstad wrote:
> > On Sunday, 9 June 2019 at 21:13:50 UTC, Manu wrote:
> >> This is NOT polymorphism, we're not talking about
> >> polymorphism, I wish people would not change the topic.
> >
> > Well, it sort of is. Consider a situation where you have
> > assignment defined for the super class, and where there is a
> > field in the subclass that depends on a field in super.
>
> Or rather: you sometimes have a dependency, then you want the
> type system to prevent assignments through the base class.
> However, in other cases you don't have a dependency, then you do
> want to be able to assign through the base class.
>
> But you need something syntactical to tell the type system that
> such dependencies exist.

Such a dependency reeks of polymorphism-proper, maybe you're using the
wrong tool?
Anyone can write bad code... if your code is brittle in that way, then
you'll find out soon enough when someone does that!
It might also be impossible to inhibit direct assignment of the base.
There may be some practical limitations that we can design that make
such mistakes relatively less unlikely or easy to catch.



More information about the Digitalmars-d mailing list