delegates vs functions => practical consequences
Mirko Pilger
pilger at cymotec.de
Wed Apr 18 15:50:16 PDT 2012
> I want to know what is most interesting for me: delegates or functions.
> I consulted sources but none say the practical consequences of such
> election.
in addition to what john said: regarding _function literals_ the
difference is by using a delegate instead of a function you have access
to the enclosing frame, e.g. variables in the same scope.
the following code doesn't compile with the error "[...] cannot access
frame of [...]":
int y;
auto fn= function(int x) {return x+y;};
if you change this to:
int y;
auto fn= delegate(int x) {return x+y;};
it compiles without error.
More information about the Digitalmars-d-learn
mailing list