version of this book
To construct this hierarchy the C ++ construct of class and member function is particularly useful. To formalize the construction it is helpful to be able to talk about such constructs directly. We can regard a class definition as a TM program that accepts multiple parameters. The first parameter is the instance of the class. This is values for all the fixed data elements in the class. The second parameter is a class member function name. The remaining parameters, which there can be any finite number of, are the parameters of the member function. When a complete set of parameters are specified an output object is computed (or the member function runs forever). It is possible to define a void member function that has no output but, for example changes its input. We will not use such constructs in the formalization. There can be different interpretations of a member functions output but the interpretation is fixed for each specific member function.
Classes can be derived from base classes and member functions can be overloaded. When a class is derived all the member functions of the base class are inherited and can be called from the derived class. A virtual function can be redefined in a derived class. If the virtual function is called then the version from the highest level class that defines the function will be invoked. The lower level member functions with the same name will be ignored.
We will denote the invocation of a class member function as:
class_instance->class_name::member_functions( parameters ).
This is standard C ++ notation except the `class_name::' part is optional and seldom used. The compiler can find the class name by looking up the class_instance in a table. (One must use this notation if one wants to call a virtual function for a specific class and ignore any higher level virtual functions with the same name.) We will also leave out the class name whenever the class is obvious.
There are several other relevant aspects of C ++ syntax. Every object in C ++ has a type. A class instance object has the type of the class. There are several built in types such as integer ( int) and floating point ( float). The only type we will use aside from classes we define is very_long . This will represent an arbitrarily large integer. To implement it with arbitrary size require a class very_long. Here we will define it to be a 64 bit integer. If necessary an appropriate class can be defined to fully implement it.
Member functions names can be overloaded. There can be two member functions with the same name but with different parameters. The function called is determined by the number and types of parameters. A member function can be a standard operator in the language. One can define a member function operator+ . This describes what operation to perform whenever two class objects, a and b appear in an expression such as a+b. (By using this feature we can define a class very_long that does arbitrary size arithmetic for all the standard arithmetic operations.) There can be a member function operator() . This defines the routine to call whenever one writes class_object( parameter).
version of this book