Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!decwrl!armada!becher From: becher@armada.UUCP (Jonathan D. Becher) Newsgroups: gnu.g++ Subject: Re: Pointers to member functions Message-ID: <116@armada.UUCP> Date: 7 Jun 89 23:06:39 GMT References: <29523@ucbvax.BERKELEY.EDU> Reply-To: becher@zaphod.UUCP (Jonathan D. Becher) Organization: we don' need no steekin' organeezation Lines: 37 In article <29523@ucbvax.BERKELEY.EDU> Marc Singer writes: >How does one call a member function using a pointer to that function? > ... >Ahem. It did not work. > >Marc Singer Early versions of C++ did not support pointer to member functions. If you look closely at the very small print on the bottom of page 154 in Stroustrup's book, he describes how pointer to member functions can be declared and used. Basically, it looks like this: class classname { char memberVar; public: void memberFunc (int param) { memberVar = param; } }; typedef void (classname::*ptrToMemFunc)(int); main() { ptrToMemFunc pf1 = &classname::memberFunc; classname instance; // call memberFunc with parameter 2 (instance.*pf1)(2); } This works in G++ 1.25.0 (and newer versions, I assume). Jon Becher argosy!becher@decwrl.dec.com "Read the fine print carelessly; you never know what you will find"