`alias x = v.x;` not working in struct bodies?

Danilo codedan at aol.com
Sat Jan 20 22:25:35 UTC 2024


On Saturday, 20 January 2024 at 22:16:35 UTC, Steven 
Schveighoffer wrote:
> So how do you do it?
>
> ```d
> struct Vec3
> {
>    Vec2 v;
>    ref x() => v.x;
>    ref y() => v.y;
> }
> ```
>
> It's not perfect, as taking the address of `x` will yield a 
> delegate, and not a pointer to the member, but it's the best 
> you can do.

Thanks Steven! Of course you all are able to concentrate on the
details of how it is implemented, because you work on that level 
every day.

If you step back to see the bigger picture, it is very intuitive 
to write:
```d
alias x = v.x;
alias y = this.v.y;
```
It means giving an `alias name` to an entity, and I think it's 
not hard to understand that.
It's just logical in a broader sense, when you look at the bigger 
picture. ;)


More information about the Digitalmars-d mailing list