Ptrs to functions (gcc vs. egcs)

Jeroen Dobbelaere Jeroen.Dobbelaere@tvd.be
Wed Mar 31 23:46:00 GMT 1999


Bob McWhirter wrote:
> 
> On Sat, 27 Mar 1999, Mike wrote:
> 
> > On 27 Mar 1999, Jason Merrill wrote:
> >
> > > Just change
> > >
> > >   ptr();
> > >
> > > to
> > >
> > >   this->*ptr();
> > >
> > > Jason
> > >
> >
> > This doesn't seem to fix it. Same error message results.
> 
> I've tended to us:
> 
>         this->(*ptr)();
> 
> Which might or might not work for you.
> 
>         -B

The C++-Faq lite[1] told me to use 

  (this->*ptr)();

or

  ((*this).*ptr)();

In fact, they propose defining a macro to make the call look cleaner [2] :

  #define callMemberFunction(object,ptrToMember)  ((object).*(ptrToMember)) 

  callMemberFunction(*this, ptr)();

Greetings,

Jeroen Dobbelaere

[1] < http://www.informatik.uni-konstanz.de/~kuehl/cpp/cppfaq.htm/ >
[2] < http://www.informatik.uni-konstanz.de/~kuehl/cpp/cppfaq.htm/pointers-to-members.html >



More information about the Gcc mailing list