C++ member function pointers in ISO C++
Nathan Sidwell
nathan@codesourcery.com
Thu Jan 11 05:30:00 GMT 2001
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
More information about the Gcc
mailing list