UFCS doubt

Antonio antonio at abrevia.net
Thu Jul 8 22:24:26 UTC 2021


In this example (extracted from 
https://digitalmars.com/articles/b68.html), this works:
```
class C {
   int a;
   int foo(int i) { return i + a; }
}

auto mfp = (C self, int i)=>self.foo(i);

void main(){
   auto c = new C;
   assert( c.mfp(20)==20);
}
```

but this fails

```
class C {
   int a;
   int foo(int i) { return i + a; }
}

void main(){
   auto mfp = (C self, int i)=>self.foo(i);
   auto c = new C;
   assert( c.mfp(20)==20);
}
```

onlineapp.d(9): Error: no property `mfp` for type `onlineapp.C`

I supossed  that ```mfp(c,20)``` and ```c.mfp(20)``` should be 
equivalent because UFCS in second example, but it is not... why?




More information about the Digitalmars-d-learn mailing list