Newsgroups: comp.lang.c++ Path: utzoo!utgpu!cunews!bnrgate!scrumpy!smithwicks!stu4 From: bnrmtl!stu4@larry.mcrcim.mcgill.edu (Craig Jones) Subject: Re: Pointers to member functions... Message-ID: <1991Jan22.202756.1801@scrumpy@.bnr.ca> Followup-To: Passing pointers to member functions Keywords: pointer, class, function Sender: news@scrumpy@.bnr.ca (USENET (Sandy Young)) Reply-To: bnrmtl!stu4@larry.mcrcim.mcgill.edu Organization: Bell Northern Research Montreal, Canada. Date: Tue, 22 Jan 91 20:27:56 GMT This is in reference to an earlier posting I made asking how to pass pointers of member functions (specifically to ftw()). Here is an example of how to do it (based on many replies to my plea) .... #include #include // Class Definition class fooclass { public: static int greeting(char*, struct stat*, int); // ^^^^^^ NECESSARY TO BE ABLE TO PASS THIS FUNCTION // TO ftw() void call_ftw (); void call_ftw2(int (*function)(char*, struct stat*, int)); }; void fooclass::call_ftw() { int return_int; return_int = ftw ("..", &fooclass::greeting, 10); } void fooclass::call_ftw2 (int (*function)(char*, struct stat*, int)) // // Calls ftw() and passes a pointer to the function to ftw. // { int return_int; return_int = ftw ("..", function, 10); } int fooclass::greeting(char* path, struct stat* status, int number) { cout << "Now in greeting " << path << "\n"; return 0; } // NON member function definition int nonclass_greeting (char* path, struct stat* status, int number) { cout << "Now in non class greeting " << path << "\n"; return 0; } main() { fooclass fooobj; // Call member function that calls ftw with a pointer to a // member function fooobj.call_ftw(); cout << "\n Now going to do next...\n\n"; // Pass outside function as a pointer to be used inside a class member function fooobj.call_ftw2(nonclass_greeting); } Many thanks for all the help that was given. ----------------------------------------------------------- Craig Jones bnrmtl!stu4@larry.mcrcim.mcgill.edu Bell Northern Research, Montreal. -----------------------------------------------------------