pointer to member without 'this' - mem_fun like
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Tue Mar 18 03:18:47 PDT 2008
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...
> 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.
More information about the Digitalmars-d-learn
mailing list