Bug 11235 - pointer to memer function
Summary: pointer to memer function
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.2
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-18 13:53 UTC by adrin_jalali
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description adrin_jalali 2003-06-18 13:53:49 UTC
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.
}
Comment 1 Wolfgang Bangerth 2003-06-18 14:01:27 UTC
gcc is just right. A member function has type
  bool (test::*) (int *)
and so doesn't match the argument of fun().

W.
Comment 2 adrin_jalali 2003-06-18 14:49:34 UTC
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
Comment 3 Andrew Pinski 2003-06-18 14:54:16 UTC
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
>
>

Comment 4 Wolfgang Bangerth 2003-06-18 15:33:22 UTC
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.