pointer to member without 'this' - mem_fun like
Vlad
b100dian at gmail.com
Tue Mar 18 03:35:20 PDT 2008
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?
>> Furthermore, does a similar mechanism for data members exist?
>
> No. You could hack something together with pointer arithmetic, but it
> won't be pretty. Some kind of wrapper could perhaps be written as a
> struct template though.
Yeah, that was silly of me:). I will be using 'setters' and revert to
the previous answer.
Thank you very much!
Vlad
More information about the Digitalmars-d-learn
mailing list