delegate as memeber
Vladimir Panteleev
vladimir at thecybershadow.net
Tue Feb 21 07:32:19 PST 2012
On Tuesday, 21 February 2012 at 15:22:15 UTC, deadalnix wrote:
> struct stuff {
> private Exception delegate() exceptionBuilder = delegate
> Exception() {
> return new Exception("foobar");
> };
> }
>
> The following piece of code trigger a compiler error : delegate
> module.stuff.__dgliteral1 function literals cannot be class
> members
>
> Why is that ? Is it a bug or a feature ?
Delegates contain a context pointer. Your delegate literal has no
context.
You can't initialize it with the address of a method, either. For
struct methods, the context pointer is a pointer to the
structure. You can't have a .init that contains a pointer to an
instance. You probably want to use a function literal.
More information about the Digitalmars-d-learn
mailing list