structs, classes, interfaces - Part III, Solution
Janice Caron
caron at serenityfirefly.com
Wed Sep 5 00:39:33 PDT 2007
-----Original Message-----
From: digitalmars-d-bounces at puremagic.com
[mailto:digitalmars-d-bounces at puremagic.com] On Behalf Of Reiner Pope
Sent: 04 September 2007 23:34
To: digitalmars-d at puremagic.com
Subject: Re: structs, classes, interfaces - Part III, Solution
I think it makes sense in the first place because one of alias's meanings is
"give the first symbol another name." In the case of "alias B this", you are
giving B the name, "this". Since all member accesses and member functions are
of the form
this.foo
or
this.func()
(but the "this." may be omitted) it makes sense that if B gets the name "this",
then it behaves like a member (as far as calling goes).
I definitely prefer the syntax
struct B : A
{
}
instead of
struct B
{
A a;
alias a this; // or any other variant such as A this
}
I would also like the following to work:
B b;
auto a = cast(A)(b); // syntactic sugar for auto a = b.a;
More information about the Digitalmars-d
mailing list