On Monday, 16 March 2020 at 18:43:47 UTC, Steven Schveighoffer
wrote:
enum A0 = &A.d;
Note that you can't call it at all, but you can get the
function pointer, and put it into a delegate later by assigning
.funcptr.
void main()
{
A a;
void delegate() dg;
dg.ptr = &a;
dg.funcptr = A0;
dg(); // calls a.d()
}
-Steve
Thanks for the tips, Steve.
I need to put them into a big const struct to use on runtime, so
they can not be modify on runtime by mistake.
I can not put the address into enum, because Error: need this
to access d
add cast(void*) still get same error:
enum callee_ptr = cast(void*) &(__traits(getMember, A, "d")); //
Error: need this to access d
but I come up with a workaround:
static void* getCallee() pure @nogc nothrow {
enum callee_ptr = &(__traits(getMember, App, name));
return callee_ptr;
}
__gshared const AppHelper APP_HELPER = {&getCallee, ..};