Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!claris!apple!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.lang.c++ Subject: Re: C++ enhancements Message-ID: <7757@apple.Apple.Com> Date: 22 Mar 88 23:11:00 GMT References: <2781@mmintl.UUCP> Reply-To: lsr@apple.UUCP (Larry Rosenstein) Organization: Advanced Technology Group, Apple Computer Lines: 45 In article <2781@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes: >Following are some suggestions for improvements to C++. > >Add a new keyword "leaf" to the language. This is applied to a (virtual) >function declaration to indicate that the function is not redefined in any >subclass of the current class. This enables the translator to generate a >direct call to the function for objects known to be in the current class. I In MPW (Object) Pascal, the linker does this automatically by analyzing the classes you define. I wouldn't want to use this as an efficiency technique, because it requires that the programmer defining the virtual member function decide whether anyone will want to override it. As a way of preventing people from overriding a member function, it is a good idea. A related idea would be to declare a virtual member function as abstract (Smalltalk calls this subclassResponsibility). This would be a function that must be overridden in all subclasses, and has no implementation at the point where it is first defined. The purpose of such a function would be to define behavior that all subclasses must follow (eg, all Shape objects must Draw). Another (unrelated) addition I would like to see is something like a delayed method call. My idea would be to package up an object and a virtual function name into an Invocation object. These objects could be passed around and stored, and at some later time you could cause the function to be called with the given object. (Suppose that the function takes no parameters.) You could use this to attach actions to a screen button, for example. The same Button object could be used to do different things depending on the Invocation object it contained. (In Smalltalk, you can do this by creating a block context, or by using an arbitrary Symbol as the name of a method to execute.) Without knowing how CFront is implemented, it seems that you could hack this if you know how CFront assigns names. This would be highly implementation-dependent, however. -- Larry Rosenstein, Object Specialist Apple Computer, Inc. 20525 Mariani Ave, MS 32E Cupertino, CA 95014 AppleLink:Rosenstein1 domain:lsr@Apple.COM UUCP:{sun,voder,nsc,decwrl}!apple!lsr