Getting the address of a member function at compile time inside a member function

Walter Bright newshound2 at digitalmars.com
Sun Jul 6 03:47:07 UTC 2025


When taking the address of a member function, a delegate is created, not a 
function pointer. The delegate is comprised of two members: a function pointer, 
and a context pointer (i.e. `this`). When the static fn is initialized, there is 
no `this` available at compile time, so it (correctly) fails to compile.

The workaround you figured out is pretty clever! I don't think you'll be able to 
do better.


More information about the Digitalmars-d mailing list