how to do member function pointer in D?

u e at mail.com
Thu Jul 31 00:10:27 PDT 2008


== Quote from Kirk McDonald (kirklin.mcdonald at gmail.com)'s article
> u wrote:
> > Go back to my original question:
> >
> > How to create a variable which hold a particular function pointer of a class, and
> > can be invoked on different objects of that class:
> >
> > fp = &(A.f);
> > A a1, a2;
> > a1.fp();   // how to make this invocation work?
> > a2.fp();
> >
> > And I have one more requirement that even if A.f() and A.g() have same signature,
> >
> > fp = &(A.g);   // expect compiler report error here.
> >
> > How to declare the type of such fp?
> There is a current thread in digitalmars.D.learn titled "Pointer to
> member variable again." It has turned into a discussion of this very topic.

I had hoped that D will offer better solution than C++'s member function pointer.

Looks like currently it's more difficulty to do what I want in D.

Probably I will live with the wrapper function for now.



More information about the Digitalmars-d mailing list