File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -3379,9 +3379,6 @@ void main()
33793379{
33803380 Foo f = {7};
33813381 int delegate() dg = &f.get; // bind to an instance of Foo and a method
3382- assert(dg.ptr == &f);
3383- assert(dg.funcptr == &Foo.get);
3384-
33853382 int i = add1(dg);
33863383 assert(i == 8);
33873384
Original file line number Diff line number Diff line change @@ -717,24 +717,28 @@ $(I function pointer) value as a function type.
717717
718718$(P Delegates are declared and initialized similarly to function pointers:)
719719
720- $(SPEC_RUNNABLE_EXAMPLE_COMPILE
720+ $(SPEC_RUNNABLE_EXAMPLE_RUN
721721-------------------
722- int func(int);
723- int function(int) fp; // fp is a function pointer
724- int delegate(int) dg; // dg is a delegate to a function
722+ void func(int) {}
723+ void function(int) fp; // fp is a function pointer
724+ void delegate(int) dg; // dg is a delegate to a function
725725
726726class OB
727727{
728- int member(int);
728+ void member(int) {}
729729}
730730
731731void main()
732732{
733733 OB o = new OB;
734734
735735 fp = &func; // fp points to function `func`
736+
736737 dg = &o.member; // dg is a delegate to object `o` and member function `member`
737- dg = (int i) => o.member(i); // dg is a delegate to main's context and a delegate literal
738+ assert(dg.ptr == cast(void*) o);
739+ assert(dg.funcptr == &OB.member);
740+
741+ dg = (int i) { o.member(i); }; // dg holds a delegate literal with main's execution context
738742}
739743-------------------
740744)
You can’t perform that action at this time.
0 commit comments