What am I doing wrong here?
Salih Dincer
salihdb at hotmail.com
Sat May 7 02:29:59 UTC 2022
On Friday, 6 May 2022 at 18:04:13 UTC, JG wrote:
> ```d
> //...
> struct Adder {
> int a;
> int opCall(int b) { return a+b; }
> }
> auto adder(int a) {
> auto ret = Adder.init;
> ret.a=a;
> return ret;
> }
>
> void main() {
> auto g = adder(5);
> g(5).writeln; // 10
> auto d = toDelegate!(int, int)(g);
> d(5).writeln; // 10
> // ...
> }
> ```
The value returned by the delegate structure in the above line is
10. Its parameter is 5, but if you do it to 21, you will get 42.
So it doesn't have the ability to delegate Adder.
In summary, the sum function isn't executing. Instead, its value
gets double.
SDB at 79
More information about the Digitalmars-d-learn
mailing list