$ dmd -c memberfunptr.d
memberfunptr.d(9): Error: cannot implicitly convert expression (__funcliteral1) of type void function(A) to invariant(void function(A))
$ cat memberfunptr.d
==========================================
import std.stdio;
class A {
void f() {writefln("f()");}
void g() {writefln("g()");}
}
alias void function(A) FP;
invariant FP mfp1 = function void(A obj) {obj.f();}; // why this doesn't work?
// the following compiles, but ugly
static invariant FP mfp2;
static this() {
mfp2 = cast(invariant FP)(function void(A obj) {obj.g();});
}
==========================================
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=74330
Why a function literal is not a constant expression?
Especially after I defining a global top level wrapper function in this case.
Under the hood, it should just be a raw pointer to some memory address, why this
cannot be a constant?