pointer to member without 'this' - mem_fun like

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Mar 18 04:39:06 PDT 2008


Vlad wrote:
> Frits van Bommel wrote:
>> Vlad wrote:
>>> Hi list,
>>>
>>> I was wondering if D has something like C's mem_fun, where one can 
>>> pass a pointer to a member function of a class, that later can be 
>>> called with various 'this' instances.
>>
>> No, sorry.
>> It does have delegates, but then the vtable lookup is performed when 
>> the delegate is constructed. If that's okay, (i.e. if you only use 
>> this for instances of the same type or subtypes that don't override 
>> that method) you should be able to take a delegate and assign a new 
>> 'this' (.ptr) to it before calling it...
>>
> 
> Thanks, this should do it - however I still need an(other) instance when 
> passing the delegate, right?

You *might* get away with using &Class.memberfn to fill in dg.funcptr. 
But I've never tried this, so you might want to make sure it works 
before using it for anything serious.


More information about the Digitalmars-d-learn mailing list