Help the old man learn D
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 26 10:11:52 PDT 2015
On Friday, 26 June 2015 at 16:57:14 UTC, Charles Hawkins wrote:
> Sorry for talking to myself, but I'm hoping someone will help
> me out. The above idea doesn't work. It appears that only the
> main program file is going to have function pointers while
> modules and classes will have delegates. So, does a library
> that uses callbacks need 2 callback register functions as well
> as parallel storage mechanisms, or is there a fairly simple way
> to make it polymorphic? I was hoping a newbie would be able to
> use this library, but not many newbies are going to understand
> this. I suppose I could tell them to call registerFunction and
> if they get a compiler error, then call registerDelegate? Or
> am I missing something?
I don't fully understand what you're doing, but functions can
easily be turned into delegates using std.functional.toDelegate
[1]:
import std.functional : toDelegate;
registerDelegate((&topLevelFunction).toDelegate);
[1] http://dlang.org/phobos/std_functional.html#.toDelegate
More information about the Digitalmars-d-learn
mailing list