Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!jarthur!petunia!kestrel.edu!gyro From: gyro@kestrel.edu (Scott Layson Burson) Newsgroups: comp.lang.c++ Subject: Re: C++ Limitation Keywords: C++ Message-ID: <1991May24.171520.17478@kestrel.edu> Date: 24 May 91 17:15:20 GMT References: <1991May14.155950.4336@infonode.ingr.com> Organization: Kestrel Institute, Palo Alto, CA Lines: 27 In article <1991May14.155950.4336@infonode.ingr.com> allgood@greg.b17a.ingr.com writes: > I would like to have the capability of telling some object A, to send >message M to an object B where M and B are not specifically known to A. >For example, I would like to create a ScrollBar and tell it "Hey, when >you get scrolled to a new location, send a 'move_to' message to this >instance of class View". I can do this in C++ if the ScrollBar class knows >about the View class, but I want to create a generic ScrollBar which >can send messages to classes which will be defined later. A proposal that either has or will soon come before the committee addresses this concern. The idea is to generalize the notion of a pointer to function so that it can carry a `this' pointer along with it. Then given an object `x', with member function `f', the value of `x.f' (or `&x.f') is a functional object which, when invoked, performs the `f' operation on that particular `x'. (In some circles this is called a "closure".) The reason this is relevant is that the *type* of such a pointer to function is determined only by the signature of the member function from which it was created; it is *independent* of the class that created it (if any). Therefore it forms a mechanism for allowing communication between objects that do not know each other's type; all that is required is for one or more of these generalized pointers to functions to be passed from one object to the other at runtime. -- Scott Gyro@Reasoning.COM