On Thursday, 18 September 2014 at 17:49:34 UTC, H. S. Teoh via
Digitalmars-d wrote:
I'm trying to write a struct with delegate member variables that I want to default to do-nothing stubs (rather than null function pointers that
will crash when called), but it appears that such a thing is not
supported.
[...]
Is there a way to achieve this?

Here's a hack:

struct S
{
     union
     {
         struct
         {
             void* contextPtr;
             void function(dchar, void* contextPtr) funcPtr = (a,
ignored) {writeln(a);};
         }
         void delegate(dchar) dg;
     }
}

Reply via email to