Check out the new USENIX Web site. next up previous
Next: Restrictions Up: Accessory Functions Previous: Accessory Functions


Syntax

We need syntactic mechanisms to identify the parameter to be used in dynamic dispatch and to specify that a superclass function should be selected during a call in a subclass function. In this article, we give a syntax that is an extension of C++, and focus on definitions that are appropriate for C++, though accessory functions could be added to other statically typed single-dispatch object-oriented languages.

We identify an accessory function by using the keyword virtual in the declaration of a parameter. We consider virtual to be an attribute of a parameter rather than an attribute of the function itself. When virtual is used in the traditional way, we say that the member function has a virtual receiver (rather than a virtual parameter). Accessory functions for C++ may be created outside of any class, as in Figure 2, or they may be created as members (or friends) of one (or more) classes.

When an accessory function for a subclass needs to make use of the superclass function, it gives explicit type information for the virtual parameter. We use syntax that is similar to type casting for this purpose (we chose this notation because it produces the result that type casting of a reference produces for a statically dispatched function). To avoid introducing a new keyword, we reuse the word ``virtual'' for this purpose, i.e. the interpret function for Num could call the superclass function (were it not pure virtual) with the syntax interpret( (virtual Exp) n ). This is only legal if the new type is a public superclass of the argument type; its effect is analogous to using interpret( (Exp &) n ) for a statically dispatched function.


next up previous
Next: Restrictions Up: Accessory Functions Previous: Accessory Functions

2000-12-09