Đang chuẩn bị liên kết để tải về tài liệu:
A Complete Guide to Programming in C++ part 62
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
A Complete Guide to Programming in C++ part 62. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | MULTIPLY-DERIVED CLASSES 589 A class can contain not just one but several different base classes. In this case the class is derived from multiple base classes in a process known as multiple inheritance. The Multiply-Derived Class MotorHome This class Car is used to represent vehicles and the class Home contains characteristic values for an apartment such as floor space number and type of rooms and typical operations such as building selling or renting. Using these two classes you can then derive the MotorHome class. The opposite page shows the inheritance and definition schemes for the new class. An object of the MotorHome class contains both the members of Car and the members of Home. More specifically the object contains two base sub-objects of type Car and Home. Accessibility of Base Classes Since the MotorHome class has two public base classes it assumes the public interfaces of both classes. A MotorHome type object not only allows access to the additional public members but to all the public members of the base classes Car and Home. When defining a multiply-derived class the accessibility private protected or public must be defined separately for each base class. The MotorHome class could have the public base class Car and the protected base class Home. Example class MotorHome public Car protected Home . . . If the keyword is omitted the base class will default to private. Example class MotorHome public Car Home . . . This statement defines the public base class Car and the private base class Home. This makes all the public members in Home private members of the derived class. In multiple inheritance each public base class establishes an is relationship. This is similar to simple inheritance. If the MotorHome class inherits two public base classes a motor-home is a special kind of motor vehicle and a special kind of home. 590 CHAPTER 27 MULTIPLE INHERITANCE MULTIPLE INDIRECT BASE CLASSES The multiple indirect base class Car Definition scheme of class suv class