Defaulting delegate member variables to do-nothing stubs

anonymous via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 18 12:16:39 PDT 2014


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;
      }
}


More information about the Digitalmars-d mailing list