elf@fiji.Berkeley.EDU (Marc Singer) (06/08/89)
How does one call a member function using a pointer to that function. I understand that some may feel it is a breech of good practice since the language already has many features to eliminate the need for pointers to functions; still the problem remains. When I called a member functions using a pointer to that function, the code which normally pushes the $this pointer did not exist. Hence, the receiving prologue popped the first parameter as the $this pointer. Ahem. It did not work. I want to use a member function because I want the function to be an implicit intimate to the private parts of the class. Simulating the $this pointer would be acceptable. Marc Singer "When fullness is taken from fullness, fullness still remains." Invocation of the Isha Upanishad
becher@armada.UUCP (Jonathan D. Becher) (06/08/89)
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"
lauwers@orc.olivetti.com (Chris Lauwers) (07/21/89)
A while ago, there was a discussion in this newsgroup about storing pointers to member functions. Michael Tiemann mentioned that C++ 2.0 compilers were going to have full support for doing this. Does this mean that g++-1.35 supports this feature? If so, how is it used? If not, can somebody summarize the temporary hacks that work for now. Thanks, Chris Lauwers Olivetti Research Center lauwers@orc.olivetti.com