Struct inheritance
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Wed Dec 4 21:49:02 UTC 2024
On 05/12/2024 6:22 AM, Derek Fawcus wrote:
> I want a way to reinterpret parent methods as if it was in the child
> if not overriden. At which point |method1| would see the child |
> method2| rather than the one in the parent.
>
> Isn't that simply what I described as 'madness' above?
>
> One would seem to be exposing the Parent method to an unexpected code
> change, as one can not know what other Parent private state may be
> updated based upon the call to method2 being changed.
> That strikes me as causing non-determinism.
>
> I could see a use for this sort of thing:
>
> |struct Parent { void method1() { method3(); } void method2() { } void
> method3() { } } struct Child : Parent { override void method2()
> { method1(); } override void method3() { } } |
>
> Where the Child call from method2() to method1() invokes the Parent
> version, yet the Parent call from method1() to method3() will only ever
> invoke the Parent version.
>
> That means the behaviour of Parent stays consistent. To allow method3()
> to be redirected, is classful behaviour, and should not be forced upon
> an existing library of structs just because of what the child did.
>
> If one wants classes, use classes - as that sort of result is expected
> to be possible there.
You need this for things like serialization.
Since we don't have runtime reflection it has to be done at CT, and if
you have to do anything to offer it as a user, its just a NOPE compared
to other languages.
Its needed for both structs and classes.
More information about the dip.ideas
mailing list