Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!cs.dal.ca!aucs!880716a From: 880716a@aucs.uucp (Dave Astels) Newsgroups: comp.lang.c++ Subject: Re: indirect message passing Message-ID: <1990Jun1.114837.11151@aucs.uucp> Date: 1 Jun 90 11:48:37 GMT References: <1990May31.131937.25923@aucs.uucp> <41462@brunix.UUCP> Reply-To: 880716a@aucs.UUCP (Dave Astels) Organization: School of Computer Science, Acadia Univ., Nova Scotia Lines: 49 In article <41462@brunix.UUCP> sdm@cs.brown.edu (Scott Meyers) writes: >In article <1990May31.131937.25923@aucs.uucp> 880716a@aucs.uucp (Dave Astels) writes: >>I am wondering if it is possible to pass messages in C++ indirectly. > > cout << "Declaring pointers...\n"; > X *py; > py = &y; > void (X::*pxmf)(); > pxmf = X::foo; > > cout << "Calling y.foo() indirectly..."; > (py->*pxmf)(); > } > 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). The use of this: Consider a menu (for example). There is a CallBack connected to each option. When an option is selected its CallBack gets passed a `Send' message, thus invoking the proper action .. sending a message to some other object. This technique enables the construction of a very sofisticated, event-driven UI with little (if any) programming overhead to make it run, once the initial set up of all the components is performed. -- - Dave Astels Internet: 880716a@AcadiaU.CA Bitnet: 880716a@Acadia