home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!att!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!liuida!isy!isy.liu.se!svan
- From: svan@isy.liu.se (Jonas Svanberg)
- Newsgroups: comp.lang.c++
- Subject: Re: Callbacks - C++ needs an extension?
- Keywords: callback
- Message-ID: <1992Aug30.180248.1700@isy.liu.se>
- Date: 30 Aug 92 18:02:48 GMT
- References: <1893@acf5.NYU.EDU>
- Sender: news@isy.liu.se (Lord of the News)
- Reply-To: svan@isy.liu.se
- Organization: Linkoping University
- Lines: 45
-
- I acknowledge checker@acf5.NYU.EDU (checker) for a nice solution
- to the callbackproblem:
-
- Every class that want to receive direct callbacks must declare an
- own callback class which inherits from some sort of systemclass
- CallBack or whatever. In this derived class one defines a new
- constructor and overloads one memberfunction. These new member-
- functions contain typinginformation about the receiver of the
- callback, so this will work and it is safe.
-
- This can be nicely done with templates I suppose, but it still
- seems like hard work to me.
-
- I have got another solution in comp.windows.open-look from
- imp@solbourne.com (Warner Losh):
-
- > In OI, you can regstier a C or a C++ style callback. Just an
- > overloaded call. For example,
- > OI_menu_cell *cellp;
- > MyClass *mcp;
- >
- > // call ::foo when button activated.
- > cellp->change_action( &foo );
- >
- > // call MyClass::bar when button activated
- > cellp->change_action( mcp, (OI_action_memfnp) &MyClass::bar );
-
- My presumption is that the type OI_action_memfnp is a pointer-to-member-of-
- -baseclass-of-MyClass. My question is:
-
- Is it safe to make the call (obj->*membfun)() when both the obj* (of class
- A) and the membfun* have been casted from respectively:
- 1. a pointer to a class derived from A and (the obj*)
- 2. a pointer to a member of a class derived from A (the memfun*)
- ?
-
- Cast #1 above can be done implicitely of course, but #2 has to be
- done explicitely if I have understood things correctely...
-
- --------------------------------------------------------------
- Jonas Svanberg
- Department of Electrical Engineering
- Linkvping University
- S-581 83 Linkvping, Sweden Email: svan@isy.liu.se
- --------------------------------------------------------------
-