This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ member function pointers in ISO C++
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Subject: Re: C++ member function pointers in ISO C++
- From: Davy Durham <david dot durham at wcom dot com>
- Date: Thu, 11 Jan 2001 09:58:04 -0600
- Cc: Terry Barnaby <terry at beam dot demon dot co dot uk>, gcc at gcc dot gnu dot org
- Organization: WorldCom
- References: <3A5DB173.337F83C8@beam.demon.co.uk><3A5DB5B1.81246387@codesourcery.com>
Okay.. I did what you said... but how to I call a method that I have the
address of
When I tried to call it in main it said I wasn't in a class scope, so I tried
calling it in different method from the class and it said I have to use .* or
->*
I'm trying to figure out just how to specify the object pointer for the method
I'm calling....
I have the ISO standard, you can point me to a section if you want..
Thanks,
Davy
Nathan Sidwell wrote:
> Terry Barnaby wrote:
> >
> > We are trying to compile some library code that passes the address of an
> > objects member
> > function together with the objects address to be used in a call-back
> > method. Having upgraded
> > to GCC 2.96 we now get a compilation error " ISO C++ forbids taking the
> > address of a
> > non-static member function to form a pointer to member function. Say
> > `&A::Func1'"
> >
> > Questions:
> > 1. Is there a proper way in ISO C++ of passing and storing a pointer to
> > a member function ?
> yes see 5.3.1/3 a pointer to member is only formed with an explicit
> & is used and its operand is a qualified-id not enclosed in parentheses.
> See also 13.4. gcc 2.95.2 could give this warning too early, when static
> and non-static member fns have the same name, and overload resolution gets
> the static member fn.
> you have to write &Class::member, not Class::member (no decay to ptr),
> not &(Class::member), not &member in a member of Class.
>
> > 2. Is there a compiler switch or other mechanism to allow the previous
> > GCC behaviour ?
> -fms-extensions IIR
>
> nathan
>
> --
> Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
> 'But that's a lie.' - 'Yes it is. What's your point?'
> nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org