Bug? aliasing member of instance
Steven Schveighoffer
schveiguy at yahoo.com
Mon Oct 24 08:20:53 PDT 2011
On Sat, 22 Oct 2011 03:28:53 -0400, Nick Sabalausky <a at a.a> wrote:
> Is this a compiler bug?
>
> --------------------------------
> struct Foo
> {
> int a;
> }
>
> Foo foo;
> alias foo.a b;
>
> void main()
> {
> b = 5; // <-- Error
> }
> --------------------------------
>
>> dmd test.d
> test.d(11): Error: need 'this' to access member a
>
> I did this on DMD 2.055
alias works on *symbols* not data.
For example, if Foo has a function bar(), aliasing foo.bar is equivalent
to aliasing Foo.bar. You are aliasing the *function* not the *delegate*.
So naturally, it would make sense that aliasing foo.a is equivalent to
aliasing Foo.a, or the symbol that accesses the member 'a' in an instance
of 'Foo'.
I would expect this may work:
void main()
{
foo.b = 5;
}
-Steve
More information about the Digitalmars-d-learn
mailing list