Bug? aliasing member of instance
Timon Gehr
timon.gehr at gmx.ch
Sat Oct 22 04:32:00 PDT 2011
On 10/22/2011 09:28 AM, Nick Sabalausky 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 has never worked for instance members, even if they are accessible
at compile time. The workaround for your example could be this:
ref @property b(){return foo.a;} // instead of alias foo.a b;
Another case where we currently have this meaningless error message:
struct Foo{
int a;
int foo(int res=a){return res;}
}
void main(){
Foo x;
x.foo();
}
I think that should work.
More information about the Digitalmars-d-learn
mailing list