home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!rutgers!cmcl2!acf5!checker
- From: checker@acf5.NYU.EDU (checker)
- Newsgroups: comp.lang.c++
- Subject: Re: Callbacks - C++ needs an extension?
- Keywords: callback
- Message-ID: <1895@acf5.NYU.EDU>
- Date: 2 Sep 92 04:58:58 GMT
- References: <1893@acf5.NYU.EDU> <1992Aug30.180248.1700@isy.liu.se>
- Organization: New York University
- Lines: 46
-
- svan@isy.liu.se (Jonas Svanberg) writes:
- >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.
-
- When the original template classes are done correctly, there is very
- little work (either real or conceptual) to be done:
-
- // assume the correct templates are written
-
- class button
- {
- public:
- button( callback3<int,int,int> &CB );
- };
-
- This means button takes a callback that takes three ints. To call it, I
- do this:
-
- specific_callback3<my_class,int,int,int> cb(*this,&my_class::Func);
-
- button B(cb);
-
- All of the derivation and crud is already done in the template classes.
- The two lines above are the only things you ever need to write once the
- original templates are debugged (and they're pretty simple, too). I
- should stop to give credit where credit is due, a friend of mine (Rich
- Hickey) came up with the template extension to this scheme; the original
- used nested classes.
-
- >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*)
- >?
-
- I'd have to see the full declarations, but most of these casting schemes
- break badly under multiple inheritance. There are ways to do it without
- casting so they should be used.
-
- Chris
-