how to do member function pointer in D?

newbie some at where.com
Wed Jul 30 16:06:01 PDT 2008


> same solution as befor (the issue is that the only thing you can put after
> the '=' ouside of a function is a constant expression and a function litteral
> isn't one)

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?

> //at global scope (OTOH static's are globals)
> static invariant FP mfp1;
> static this()
> {
> mfp1 = cast(invariant FP)(function void(A obj){obj.f();});
> }

Thanks again. I can live with this workaround right now, but I'd really like to
write it as simple as:

invariant FP mfp2 = function void(A obj) {obj.f();};  // without the cast

> I still don't get it, what type of manipulation (outside self modifying code)

E.g. save in a hash-table, or use them as keys ...

And I'd really like to do self modifying code ;-) I read somewhere that D plan
have to AST macros? so we are closer to lisp:
http://en.wikipedia.org/wiki/Greenspun%27s_Tenth_Rule

> can you do that doesn't allow switching in a different function with the
> same signature?

Yes, I do it manually (by writing program carefully). I want the help from the
type system (or the language compiler) to protect me from such violation.




More information about the Digitalmars-d mailing list