alias Error: need 'this'

bomat Tempest_spam at gmx.de
Sun Mar 19 11:52:50 UTC 2023


Hi,

I read about aliases today and thought it would be handy for 
shortening repeated access to struct members.
However, I'm clearly missing something.
Here's some example code:

```
int variableWithALongName = 42;
alias alias1 = variableWithALongName;
alias1 = 43;
assert(variableWithALongName == 43);

struct MyStruct
{
     int memberWithALongName;
}
MyStruct myStruct;
myStruct.memberWithALongName = 42;
alias alias2 = myStruct.memberWithALongName;
alias2 = 43; // does not compile, see below
assert(myStruct.memberWithALongName == 43);
```

It works fine with the `int` variable, but with the struct member 
I get a compilation error:
```
Error: need `this` for `memberWithALongName` of type `int`
```

What is that supposed to mean?

Thanks
bomat


More information about the Digitalmars-d-learn mailing list