【正文】
mbers of a class are hidden and which are part of its public interface. The members of the hidden implementation are marked in sections beginning with the keyword private. The public interface part of the class follows the keyword public. By default, the declarations within a class are private, meaning that only the member functions (and friends) of the class have access to them. A class definition does not allocate any memory. Memory is allocated when an array object is created through a variable declaration. Constructors and destructors provide the initialization and clean up of an object. When an object is declared, the constructor is called to initialize the memory used by the object. The destructor performs any cleanup for the object when the object goes out of scope and is destroyed. 10 Note that we didn39。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 and the relationships among them. When a software system is designed, a variety of objects arise, which may be related in one way or another. Some classes may not be related at all. Many times it makes sense to anize the object classes into an inheritance hierarchy. Organizing a set of classes into a class hierarchy requires that we understand the relationships among the classes in detail. Not all class relationships dictate that inheritance be used. C++ provides three forms of inheritance: public, private, and protected. These different forms are used for different relation ships between objects. To illustrate these different types of inheritance, let39。s look at several different class relationships. The first relationship is the ISA relationship. This type of relationship represents a specialization between types or classes. ISA inheritance holds for two classes if the objects described by one class belongs to the set of objects described by the other more general class. The ISA relationship is the traditional form of inheritance called subtyping. The subtype is a specialization of some more general type known as the supertype. In C++, the supertype is called the base class and the subtype the derived class. To implement the ISA relationship in C++ we use public inheritance. When public inheritance is used the public parts of the base class bee public in the derived class and the protected parts of the base class bee protected in the derived class. To implement the HASA relationship in C++ we use either position or pri