bound pointer to member
Jonathan Wakely
jwakely.gcc@gmail.com
Wed Feb 23 10:29:00 GMT 2011
On 23 February 2011 10:19, Klaus Rudolph wrote:
> Hi,
>
> I search for a simple code snipped which shows how bound pointers work.
> I always end up in the message :
>
> main.cpp:51: error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say ‘&A::Func2’
>
> Can anyone post a code snippet which compiles on g++?
$ cat bound.cc
struct Sq {
int f(int i) { return i*i; }
};
int main()
{
typedef int (*funcptr_type)(Sq*, int);
funcptr_type f = (funcptr_type)(&Sq::f);
Sq sq;
return f(&sq, 4);
}
$ g++ bound.cc -Wno-pmf-conversions
$ ./a.out ; echo $?
16
$
>Is there a need to give any special options to enable this language extension?
As stated in the manual, use -Wno-pmf-conversions to suppress a
warning, but it still works even if the warning is issued.
http://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html
More information about the Gcc-help
mailing list