digitalmars.D - delegate opCall?
- H. S. Teoh (18/19) Oct 11 2012 obj(x,y,z) will be translated to obj.opCall(x,y,z), correct? So why is
From what I understand from TDPL, given a struct or object obj, writingobj(x,y,z) will be translated to obj.opCall(x,y,z), correct? So why is it that this doesn't work: struct S { RetVal delegate(Args args) opCall; } void main() { auto s = S((Args args) => doSomething(args)); Args my_args; RetVal r = s(my_args); // this is line 7 } I get this error: test.d(7): Error: struct S does not overload () An easy workaround is to rename the delegate "impl", then implement opCall as a wrapper: RetVal opCall(Args args) { return impl.args; } But this seems unnecessarily verbose to me. T -- What's a "hot crossed bun"? An angry rabbit.
Oct 11 2012