need help to get member function const address

Calvin P changlon at gmail.com
Thu Mar 19 04:30:32 UTC 2020


I use this code to get member function address on runtime:

=========
struct A {
        this(){};
}
auto ctor = (&__traits(getMember, A.init,"__ctor")).funcptr;
=========


my question is, how to get it in compile time like static 
function address:

=========
struct A {
      void d(){};
      static void fn(){};
}

enum FN = &A.fn;  // static method address is ok
enum A0 = &(A.d).funcptr; // Error: need this for d of type void()
enum A1 = (&__traits(getMember, A,"d")).funcptr; // Error: no 
property funcptr for type void function()
enum A2 = (&__traits(getMember, A.init,"d")).funcptr; //  Error: 
(&A().d).funcptr cannot be evaluated at compile time
=========




More information about the Digitalmars-d-learn mailing list