This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ member function pointers in ISO C++

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..


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   ::   ::   CodeSourcery LLC
>          'But that's a lie.' - 'Yes it is. What's your point?'
> : :

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]