Re: general func. ptr.

New Message Reply Date view Thread view Subject view Author view

Nicolas Gauvin (nicolas++at++cae.ca)
Wed, 2 Jul 1997 10:16:55 -0400


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

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.