Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!uw-beaver!Teknowledge.COM!unix!hplabs!hp-ses!hpcuhb!hpcllla!hpclisp!hpclscu!shankar From: shankar@hpclscu.HP.COM (Shankar Unni) Newsgroups: comp.lang.c++ Subject: Re: pointer to function in varargs arguments Message-ID: <58170010@hpclscu.HP.COM> Date: 21 Mar 90 02:28:06 GMT References: <1990Mar19.190923.12448@elroy.jpl.nasa.gov> Organization: Hewlett-Packard Calif. Language Lab Lines: 40 > void (a::*func_ptr)(char*) = &a::proc; > ... > proc2(func_ptr); > ... > (proc2 is not a member function of a.) > ... > However, func_ptr is not what it seems. It is not a pointer to > proc. It is a "structure" with member f pointing to proc. Except > that you may not reference member f. So what? You don't need the actual address of a::proc in any case. Remember that since "func_ptr" points to a *member* function of class "a", you should only be calling it USING AN OBJECT OF CLASS "a" (or one of its descendants). In this case, you should be using the ->* or .* operator to call the function. #include class a { public: void proc(char *x) { printf ("a::proc: \"%s\"\n", x); } }; void proc2 (void (a::*p)(char *)) { a *t = new a; (t->*p) ("test"); // Call through pointer-to-member-function } main() { void (a::*func_ptr)(char *) = &a::proc; proc2 (func_ptr); } ----- Shankar Unni E-Mail: Hewlett-Packard California Language Lab. Internet: shankar@hpda.hp.com Phone : (408) 447-5797 UUCP: ...!hplabs!hpda!shankar