21.02.2012 17:24, deadalnix пишет:
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 ?
The compiler expects member initializers to be known at compile-time.
Since delegate carries closure, and closure is a run-time phenomena, you
cannot put it there. That's how I understand it, and I might be wrong.
Anyway, something like this is possible as a workaround:
struct Foo {
private Exception dg() {
if( m_Dg ) return m_Dg();
return new Exception( "foobar" );
}
private Exception delegate() m_Dg = null;
}