how to do member function pointer in D?

newbie some at where.com
Wed Jul 30 10:20:43 PDT 2008


Hi,

I want to be able to create a member function pointer type from a class (not
from an object of that class), i.e.

class A {
  void f() {}
  void g() {}
}

(member function pointer) mfp = &A.f; // what's the sytax for the type?

// also I want the compiler to report error if I pass g() to mfp:
mfp = &A.g;   // type error!

// and mfp can be invoked on different object instance of A:
A a1, a2;

mfp(a1);   // call a1.f(), what's the right syntax?
mfp(a2);   // call a2.f()

Thanks.



More information about the Digitalmars-d mailing list