Path: utzoo!attcan!uunet!munnari.oz.au!uhccux!ames!think!sdd.hp.com!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!psuvax1!husc6!bbn.com!nic!hri!sparc7!roman From: roman@sparc7.hri.com (Roman) Newsgroups: comp.lang.c++ Subject: Re: indirect message passing Message-ID: <1990Jun1.201636.29720@hri.com> Date: 1 Jun 90 20:16:36 GMT References: <1990Jun1.114837.11151@aucs.uucp> <1990May31.131937.25923@aucs.uucp> <41462@brunix.UUCP> Sender: news@hri.com Reply-To: roman@sparc7.hri.com (Roman) Organization: Horizon Research Lines: 55 In article <1990Jun1.114837.11151@aucs.uucp>, 880716a@aucs.uucp (Dave Astels) writes: > [deleted] > > Yes, but I want to be able to have a class to hold the indirect call, as in: > > class CallBack { > void * instance; // address of instance to be passed the message > void * method; // entry point of the method > public: > CallBack (void *, void *); > Send (void); > } > > Then I want to be able to set up an indirect call via something like: > > CallBack cb (&y, (X::*foo)()); // is the -> member syntax correct ? > > and later perform the call by > > cb.Send (); > > I realize that this probably can't work with virtual methods (on first > consideration), but I don't think that is a problem in my case (the TP > version won't either, and it works fine for what I need). > > [deleted] > - Dave Astels > > Internet: 880716a@AcadiaU.CA > Bitnet: 880716a@Acadia The problem is not with virtuals, but with casting a method pointer to void*. After the cast the pointer is useless (you loose information necessary to call the method). What about this: class CallBack { public: virtual void Send(); }; class CallBackX : public CallBack { X* objPtr; void (X::*fPtr)(); public: CallBackX(X*,void (X::*)()); void Send() { (objPtr->*fPtr)(); } }; Unfortunatly for each X you have to define new CallBack class.