Bind object to member function

Kirk McDonald kirklin.mcdonald at
Mon Aug 14 02:01:30 PDT 2006

Li Jie wrote:
> > If you're looking for pointers to member functions to implement some
> > sort of dispatch mechanism, delegates do not directly allow this.
> Thanks.
> Delegate is very cool, but it bind too early.

My own Pyd library requires this functionality to implement its class 
wrapping. I do not endorse this practice, but the dirty hack it uses to 
get the functionality is found here:

In essense, it constructs a delegate from an Object instance and a 
regular function pointer. It takes advantage of how delegates are 
represented internally, but this behavior is not guaranteed by the spec. 
It is therefore firmly in the realm of "dirty hacks."

Note that this module requires the ftype module originally written by 
Daniel Keep. The version of ftype in Pyd is slightly modified from his 

Kirk McDonald
Pyd: Wrapping Python with D

More information about the Digitalmars-d-learn mailing list