Oh, no UFCS for member functions

Anonymouse via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 29 08:08:05 PDT 2016


On Tuesday, 29 March 2016 at 14:56:53 UTC, Luís Marques wrote:
> Too bad this doesn't work:
>
> struct Player
> {
>     MapTile[] playerMap; // partial private knowledge of map
>     Location destination;
>
>     auto tile(Location loc)
>     {
>         return playerMap[loc];
>     }
>
>     void foo()
>     {
>         if(destination.tile.hasMonster)
>             ...
>     }
> }

By design. I don't remember the rationale, though.

The ugly workaround if you really don't want to reorganise things 
(and/or use the tile function directly) is to make a top-level 
alias tile = Player.tile;


More information about the Digitalmars-d mailing list