Re: general func. ptr.

New Message Reply Date view Thread view Subject view Author view

Allen Bierbaum (bierbaum++at++cthulhu.engr.sgi.com)
Wed, 02 Jul 1997 19:24:47 -0700


It is possible to do something like this in a more "object oriented"
way. Look into using functors. In short functors are objects that act
like functions by storing information about the functions they are going
to call. Functors can be used to store a class pointer and a mumber
function pointer. Then you just pass around the functor object or a
pointer to it. This can be used with templates to allow you to write
code that can operate on any C++ function (static and non-static). I
use functors to allow sproc'ing of class member functions.

If you want further explaination, I can refer you to some references
when I get some time.

-Allen

Nicolas Gauvin wrote:
>
> On Jun 29, 3:00pm, Swapnil Shah wrote:
> > Subject: general func. ptr.
> > hi,
> >
> > I know that pointer to function and pointer to method in class is
> different.
> > Now can someone tell me how do i have some general pointer, which can
> > point to different methods of different objectes/classes ???
> > (This can be similar to base class pointer which can point to any type of
> > inherited class)
> > OR is this possible atall!!!
> >
>
> My understanding is that it is not possible to save a pointer to a true member
> function partly because of the implicit 'this' parameter. I wouldn't be
> surprised that it was forcefully prevented during the design of the
> C++ language since it is not really "object oriented". Virtual funcs are the
> way to go instead.
>
> You can still save pointers to static member functions since they are just
> like plain C functions and used them in systems that require you to provide
> callbacks. Such a function can be used as an intermediate path to a true member
> function provide that you have a way of retrieving a class pointer.
>
> Section 18 of the C++ faq discusses this whole issue in greater details.
> (rtfm.mit.edu in /pub/usenet/something)
>
> --
> Nicolas Gauvin CAE Electronics Ltd., 8585 Cote De Liesse
> 3D Graphics Software Saint-Laurent, Quebec, Canada, H4L-4X4
> nicolas++at++cae.ca Tel: (514) 341-2000 x2275, Fax: (514) 340-5496
> =======================================================================
> List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:55:34 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.