Re: bound pointer to member

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux