weird behavior returning delegate
Tom S
h3r3tic at remove.mat.uni.torun.pl
Sun Jul 2 15:39:55 PDT 2006
Carlos Santander wrote:
> Thanks for the answers. I was hoping D could be added to
> http://www.paulgraham.com/accgen.html only with three lines instead of
> something like that horrible C++ code.
It's not very bad in D:
T delegate(T) acc(T)(T i) {
class Foo {
T x;
this() { x = i; }
T func(T a) { return x += a; }
}
return &(new Foo).func;
}
or
T delegate(T) acc(T)(T i) {
auto res = new class Object {
T x;
T func(T a) { return x += a; }
};
res.x = i;
return &res.func;
}
--
Tomasz Stachowiak /+ a.k.a. h3r3tic +/
More information about the Digitalmars-d
mailing list