Making alias of a struct field needs "this".

Ali Çehreli acehreli at yahoo.com
Tue Jun 2 09:10:03 UTC 2020


On 6/2/20 1:56 AM, realhet wrote:

 > struct A{
 >    struct B{ int c; }
 >    B b;
 >
 >    auto f(){
 >      alias d = b.c;

The spec explicitly says it's not legal: "Aliases cannot be used for 
expressions" (Item 10):

   https://dlang.org/spec/declaration.html#alias

I use nested functions for such cases:

   auto f(){
     auto d() {
       return b.c;
     }
     return d;
   }

Ali



More information about the Digitalmars-d-learn mailing list