here we want to send a member function to another non-member function. but this is not possible and gcc can't pass and cast a member function to a non-member finction. here is a sample code : struct test { bool f(int *i) const {return *i > 10; } }; void fun(bool (*)(int *)); int main(void) { test temp; fun(temp.f); -> here can't be compiled. }
gcc is just right. A member function has type bool (test::*) (int *) and so doesn't match the argument of fun(). W.
Subject: Re: pointer to memer function that's true, but this code can't be compiled too, why? struct test { bool f(int *i) const {return *i > 10; } }; void fun(bool (test::*)(int *)); int main(void) { test temp; fun(temp.f); -> here can't be compiled again. } --- bangerth at dealii dot org <gcc-bugzilla@gcc.gnu.org> wrote: > PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11235 > > > bangerth at dealii dot org changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > Status|UNCONFIRMED |RESOLVED > Resolution| |INVALID > > > ------- Additional Comments From bangerth at dealii dot org 2003-06-18 14:01 > ------- > gcc is just right. A member function has type > bool (test::*) (int *) > and so doesn't match the argument of fun(). > > W. > > > > ------- You are receiving this mail because: ------- > You reported the bug, or are watching the reporter. __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
Subject: Re: pointer to memer function because the function which you are passing to fun is declared as const and that it wants a non const version, try the following: struct test { bool f(int *i) const {return *i > 10; } }; void fun(bool (test::*) (int *) const ); int main(void) { test temp; fun(&test::f); } Thanks, Andrew Pinski On Wednesday, Jun 18, 2003, at 10:49 US/Eastern, adrin_jalali at yahoo dot com wrote: > PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* > gcc-bugs@gcc.gnu.org. > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11235 > > > > ------- Additional Comments From adrin_jalali at yahoo dot com > 2003-06-18 14:49 ------- > Subject: Re: pointer to memer function > > that's true, but this code can't be compiled too, why? > > struct test > { > bool f(int *i) const {return *i > 10; } > }; > > void fun(bool (test::*)(int *)); > > int main(void) > { > test temp; > fun(temp.f); -> here can't be compiled again. > } > > --- bangerth at dealii dot org <gcc-bugzilla@gcc.gnu.org> wrote: >> PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* >> gcc-bugs@gcc.gnu.org. >> >> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11235 >> >> >> bangerth at dealii dot org changed: >> >> What |Removed |Added >> ---------------------------------------------------------------------- >> ------ >> Status|UNCONFIRMED |RESOLVED >> Resolution| |INVALID >> >> >> ------- Additional Comments From bangerth at dealii dot org >> 2003-06-18 14:01 >> ------- >> gcc is just right. A member function has type >> bool (test::*) (int *) >> and so doesn't match the argument of fun(). >> >> W. >> >> >> >> ------- You are receiving this mail because: ------- >> You reported the bug, or are watching the reporter. > > > __________________________________ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com > >
As Andrew pointed out, because of the const and because you need to write &test::f instead of test.f. I suggest you take a good C++ book. W.