On Thu, 08 Jan 2015 22:25:11 +0100 Artur Skawina via Digitalmars-d-announce <digitalmars-d-announce@puremagic.com> wrote:
> On 01/08/15 21:23, ketmar via Digitalmars-d-announce wrote: > > i'm not sure, but maybe it worth renaming "struct inheritance" to > > "extending a struct"? or even something completely different. what it > > does is actually extending/augmenting the struct, but not > > OO-inheritance, as one cannot pass "augmented" struct to the function > > which expects original struct. at least without hackery. > > 'alias this' is just the D syntax for implicit conversions. > The feature /is/ crippled, but there's no need for "hackery"; > at least not for simple things like that. > > struct A { int a; } > struct B { A a; alias a this; string b; } > > int f(A a) { return a.a+1; } > int g(ref A a) { return a.a+1; } > ref A h(ref A a) { return a; } > > int main() { > B b; > return f(b)+g(b)+h(b).a; > } > > artur mea culpa. i completely forgot about that feature of `alias this`, and was pretty sure that the code above is invalid. i never bothered to really check it. sorry.
signature.asc
Description: PGP signature