bound pointer to member

Klaus Rudolph lts-rudolph@gmx.de
Wed Feb 23 12:09:00 GMT 2011


> > 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);
> }

OK, maybe a missunderstanding or a wrong naming for my problem...

What I am searching for is the following:

class A 
{
    void AnyFunc();
}

int main()
{
   A a1;
   A a2;

   ...anyPointerDefinition ptr1;
   ...anyPointerDefinition ptr2;

   ptr1= &(a1.Func);
   ptr2= &(a2.Func);

   //call the pointers as functions
   ptr1();
   ptr2();   
}

where ptr1 and ptr2 must contain the ptr to the method and the ptr to
the object. This extension is available on borland as I know?!

Any idea?

Thanks
 Klaus
-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de



More information about the Gcc-help mailing list