【正文】
ived class. When the inheritance is protected, the public and protected parts of the base class are accessible to the member functions (the implementation) of the derived classes, but not to general users of the derived classes. Finally, when inheritance is private, the public and protected parts of the base class are only accessible to the implementer of the class, but not to users or derived classes. POLYMORPHISM in C++. Polymorphism is the last of the three fundamental primitives of objectoriented programming and the most important. Together with inheritance, polymorphism brings the most power, in terms of runtime flexibility, to objectoriented programming. Polymorphism, which means many forms, provides a generic software interface so that a collection of different types of objects may be manipulated uniformly. C++ provides three different types of polymorphism: virtual functions, function name overloading, and operator overloading. The virtual function mechanism can only be invoked through the use of a base class reference or pointer. Recall that a base class pointer can point to an object of the base type or an object of any type that is derived from the base class. Virtual functions are also used to implement the logic gate hierarchy .The class gate is an abstract base class at the root of the inheritance hierarchy. A class is considered abstract when some of its virtual member functions do not have an implementation. These functions are assigned to be zero in the class classes must provide implementations for them. Another form of polymorphism found in C++ is function overloading. A function is said to be overloaded when it is declared more than once in a program. Overloading allows a set of functions that perform a similar operation to be collected under the same name. When there are several declarations of the same function, the piler determines which function should be called by examining the return type and argument signature of the function call. 13 When we define new data types, it is often useful to define standard operations that are found in similar types. For example, a plex type also has addition and subtraction defined for it. We can use operator overloading so that the addition (`+39。). In the last two issues of ObjectiveViewPoint we have looked at how C++ supports the objectoriented paradigm. 。t really hide the implementation details from the user. C++ does not provide a way to pletely exclude all of the details of the underlying implementation, since the private part of the class must be included with the class definition it is useful to relax the access to variables within a class, particularly under inheritance. Often derived classes need easy access to the private members of their parent classes. C++ defines the keyword protected for this purpose. Protected members can be accessed by the member functions of a class as well as by member functions of derived classes. However, like private members, protected members cannot be accessed by user programs. One final note about objects. Recall that message passing is the fundamental means for munication among objects. When we write i () we are effectively sending a message to the a2 array object to determine the size of the array and return it. In actuality, no message is really sent. C++ emulates message passing through the use of function calls. The piler ensures us that the correct function will be called for the desired object. So, in C++ you can think of message passing as function calls. Objectorientation has bee a buzzword with many meanings. It is a design methodology, a paradigm (a way of thinking about problems and finding solutions), and a form of programming. As a design methodology, we can use objectoriented techniques to design software systems. But it is more than a design methodology, it is a whole new way of thinking about problems. Objectoriented design allows us to think about the actual realworld entities of the problem we are attempting to provide a solution for. Beginning the design with concepts from the real world problem domain allows the same concepts to be carried over to implementation, making the design and implementation cycle more seamless. Once a design has been conceived, a programming language can be chosen for implementation. By factoring out the inheritance relationships from the object hierarchies discovered during design, one can even implement the system in a traditional, non objectoriented language. However, using an objectoriented language, such as C++, makes it easier to realize the design into an implementation because the inherent relationships among objects can be directly supported in the language. Languages such as C++ are considered hybrid languages because they are multiparadigm languages. C++ is an object oriented extension of C and can be used as a procedural language or as an objectoriented language. In this issue, we continue our tour of the objectoriented features of C++. The ObjectOriented Features of C++ INHERITANCE in C++. One of the major strengths of any objectoriented programming language is the ability to build other classes from existing classes, thereby reusing code. Inheritance allows existing types to be extended to an associated collection of subtypes. 11 Recall that one of the key actions of objectoriented design is to identify realworld entities an